Graph you Data and Email It

I have a new website and I want to know the number of new signup every day, so I wrote a small script that will print the number of new signups today.


I ran this script daily using a cron job and add it to user.dat file:

0 0 * * *   /home/rayed/bin/ >> /home/rayed/var/user.dat

After few days the file will look like this:


I could send this file daily and read, but it wouldn’t give a good picture of how new user signup is changing by time, so the next logical step is to convert it to a graph for easier understanding.

I used gnuplot to convert the textual data to a graph, and automatically email it to me.

So I wrote the following small script,




set terminal png \
    medium \
    size 800,400;
plot  'user.dat' with lines;

img_base64=`echo $plot | gnuplot | base64`

sendmail $to_email <<EOF
From: <$from_email>
To: <$to_email>
Subject: Plot and Inline image from CLI
Mime-Version: 1.0
Content-Type: multipart/related; boundary="boundary-example"; type="text/html"

Content-Type: text/html; charset="US-ASCII"

This email sent from Linux CLI:
<IMG SRC="cid:plot_image_1" ALT="Plot">

Content-ID: <plot_image_1>
Content-Type: IMAGE/PNG
Content-Transfer-Encoding: BASE64



When you run it you will receive the following graph on your email:


Of course you can edit the email HTML template, add new graph, or do whatever you like to customise it.

I hope you find it useful.

Side note to self:
To install gnuplot with X11 support on OSX:

brew install gnuplot --with-x

Blast from the past: Small Piece of Saudi Arabia Internet History

Last week my friend Osama Aldosary was cleaning his emails and found this 13 years old email from me back when I was working as a system admin at ISU KACST, and I was administrating the email servers that accept and forward all internet emails for Saudi universities, Osama was working for KSU back then.

Thank you Osama

Subject: New Link Migration Plan
Date: Wed, 10 Feb 1999 15:34:40 +0307
From: Rayed Al-Rashed < *****>
Organization: KACST
To: *****, *****, *****, *****, *****

Salam Brothers,

As you all know KACST was connected through King Faisal Specializes
Hospital, and since KACST is now connected through ISU, we have to
replace our old IP addresses with the new ones from ISU.

Of course this will affect the leased-line link and E-Mail traffic with
all of you, and we tried to delay the migration as much as we can to
give you enough time to set up your own services through ISU link.

Our dead line to return the old IPs will end in less than a month, then
we have to return them to RIPE, we are going to start our plan to
migrate to the new IPs, and we have to stop the leased-line link and our
old mail relay that serve your domains when we return the old IPs.

I am sure that most of you are ready by now, but if you are facing any
problems we will be happy to help you with it.

Please send me the current state of your migration plan, and the
estimated time to finish.

Rayed Al-Rashed
Internet Services Unit
King abdullaziz City for Science and Technology