add cronjob to run a page on a website

Discussion in 'Programming/Scripts' started by [email protected], Mar 14, 2007.

  1. md@waw.co.uk

    [email protected] New Member

    I understand that to add a cronjob I use crontab -e

    I want to send emails to customers once a day, I have the page set-up & if I open the page in a web browser it works.

    the path is /home/www/web(number)/web/auto/mail.php

    I added this to the crontab

    00 01 * * * /home/www/web(number)/web/auto/mail.php &> /dev/null

    I think this will run at 1am every day - but it doesn't work.

    Can you tell me where I'm going wrong please.

    I have set CHMOD to 777 for the file mail.php

    Thanks
     
  2. ibux

    ibux New Member

    When running a PHP script from cron, you must run it through the php binary. When you view a PHP script in your web browser, the web server hosting the PHP file does that for you automagically.

    So to run your cron job, do something like this:
    Code:
    00 01 * * * /path/to/php /home/www/web(number)/web/auto/mail.php
    Hope that helps!
     
  3. todgerme

    todgerme Member

    you can also run a php file in lynx:

    /usr/bin/lynx [-auth user : pass] -dump -source http://domain.com/somescript.php 2>&1 > /dev/null

    the bit in []'s is optional and depends if your script is behind some sort of authentication
     
  4. ibux

    ibux New Member

    You will definitely want to add some kind of access control to that mail script.
    Use a .htaccess file in the directory to block out unauthorized users. That won't affect scripts run from a cron job or shell.

    Good luck.
     
  5. md@waw.co.uk

    [email protected] New Member

    Thanks

    Thank you

    I've made the suggested changes & hopefully that will sort it out.
     
  6. mackenga

    mackenga New Member

    If you wanted to use a cron job to hit a page via the web server, I wouldn't use lynx - lynx is great for interactive use but for this sort of thing I'd go with curl or wget.

    Just my 2 cents.
     

Share This Page