If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Emailed Counter

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-04, 18:20
philip pluckros philip pluckros is offline
Registered User
 
Join Date: Jan 2004
Posts: 17
Emailed Counter

Hi,
I am trying to write a script which can be called from CRON to email me the hits of a particular site say, once a month.
I have no ide how to do this... Please help..

This is the first time I have used Unix Shell's so please bare that in mind when responding.

Thanks,
Philip.
Reply With Quote
  #2 (permalink)  
Old 01-12-04, 04:22
chillies chillies is offline
Registered User
 
Join Date: Jul 2003
Location: Edinburgh
Posts: 35
Re: Emailed Counter

1. Understand the format of the crontab file ("crontab -l" will list current cronjobs), and decide which user shall be running the cronjob.

2. Find where the website logs are located, decide which information you want from them, and determine how to extract it (grep)

3. Ensure a mailer is installed and pipe the output from (2) to it
Reply With Quote
  #3 (permalink)  
Old 01-12-04, 18:46
philip pluckros philip pluckros is offline
Registered User
 
Join Date: Jan 2004
Posts: 17
I have actually setup a little PHP script which stores the website hit count in a .txt file.
So, I guess all I need to do is view that file or as you say pipe it to a mailer.

Yep.....


How the hell do I do that?
Im, sorry, but I have never used the Unix operating system before.
How do I know if I have a mailer installed?

Phil.
Reply With Quote
  #4 (permalink)  
Old 01-12-04, 23:47
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Quote:
Originally posted by philip pluckros
I have actually setup a little PHP script which stores the website hit count in a .txt file.
So, I guess all I need to do is view that file or as you say pipe it to a mailer.

Yep.....


How the hell do I do that?
Im, sorry, but I have never used the Unix operating system before.
How do I know if I have a mailer installed?

Phil.
Type "mail" and hit enter. If you don't get an error saying "unknown command" then you do have mail installed (use "x" command to exit mailer).

To send a file use the following:

cat yourfile.txt | mail -s "your subject line" youremail@address.com
Reply With Quote
  #5 (permalink)  
Old 01-13-04, 03:20
chillies chillies is offline
Registered User
 
Join Date: Jul 2003
Location: Edinburgh
Posts: 35
If you're phased by this talk of pipes (one of the strengths of the command line IMO) and redirection, you'll probably be unsure of what I mean by 'stdout'. My understanding of PHP is that by default the output is to stdout i.e. output from 'print' appears in the shell window after the command is run.

If your PHP script writes a text file, could you not change it so it writes its output on stdout, then pipe the output to the mailer? You'll not have to clear up the .txt file after yourself.

One thing you have to watch out for is that cron runs its commands with a restricted PATH envvar, and you should use fully-qualified command names. You should ask the sysadmin if mail is installed, and what its full pathname is.

With these two changes, the cron entry will look something like this. Oh yeah ... have you entered something in a crontab before? "crontab -e" will bring up the editor referred to in the EDITOR envvar, or vi if you're unlucky ;-)

* * 2 * * /path/to/script.php | /usr/bin/mail -s "email subject" youremail@address.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On