Email web statistics from the hosted website using awstats page.

2010-03-08 302 words 2 mins read

I want to see the stats for my websites mailed to me directly like Google analytics does. Sure enough I can see them on the hosting cpanel page on awstats, but I dont want to check that everyday. An easier solution would be to have that mailed to my email address everyday using cron. Let’s try to do that today:

First we would need to get the address of the page for the statistics, which would look like this:

http://blog.amit-agarwal.co.in/awstats.pl?config=blog.amit-agarwal.co.in

So, we download this using the wget program. We would need to supply the username and password to get to the page.  We will use to send the password and the username to get to the page :

–http-user=”” –http-password=””

Try to get the page on the command  line once with the complete command:

wget –http-user=”username” –http-password=”password” ’http://blog.amit-agarwal.co.in/awstats.pl?config=blog.amit-agarwal.co.in&ssl=&lang=en&framename=mainright’ -O /tmp/aka3 -o /dev/null

This should get the page contents onto file called /tmp/aka3. View the contents in the browser of your choice and ensure that this is what you want 🙂

Now to get the mailing part working. One option is to send the mail directly using sendmail but that will not set the mime correctly for the email and thus your client would display the source code of the page rather than the page. So, we will have to set the mime type and also set the subject line and others. So we will write a script to do that for us. Here’s the complete script:

wget –http-user=”username” –http-password=”password” ’http://blog.amit-agarwal.co.in/awstats.pl?config=blog.amit-agarwal.co.in&ssl=&lang=en&framename=mainright’ -O /tmp/aka3 -o /dev/null
cat «EOF > /tmp/aka4
To: email address
Subject: Stats for amit-agarwal.co.in on `date –iso`
Content-Type: text/html; charset=”us-ascii”

EOF cat /tmp/aka3 >> /tmp/aka4

Now run this script and you should get an email with subject : Stats for amit-agarwal.co.in on date

Now put this in cron and you are done.


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it