Results 1 to 5 of 5

Thread: Emailed Counter

  1. #1
    Join Date
    Jan 2004
    Posts
    17

    Unanswered: 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.

  2. #2
    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

  3. #3
    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •