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:
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 :
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/nullEOF cat /tmp/aka3 >> /tmp/aka4
cat «EOF > /tmp/aka4
To: email address
Subject: Stats for amit-agarwal.co.in on `date –iso`
Content-Type: text/html; charset=”us-ascii”
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.
- 2010/01/10 Send mail to yourself and read in your favourite client and configure the rules to move to directory.
- 2010/01/07 Sendmail host map failure issue with sendmail.
- 2010/01/01 Simple rss to email service for your feeds on Linux with your/ISP server.
- 2009/09/26 Configure sendmail for SMTP relay with your ISP
- 2009/09/08 Database of vulnurability at milw0rm.com – udpate and makeindex with cron.