HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Programming/Scripts (
-   -   add cronjob to run a page on a website ( 14th March 2007 21:14

add cronjob to run a page on a website
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


ibux 14th March 2007 22:10


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

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:

00 01 * * * /path/to/php /home/www/web(number)/web/auto/mail.php
Hope that helps!

todgerme 14th March 2007 23:26

you can also run a php file in lynx:

/usr/bin/lynx [-auth user : pass] -dump -source 2>&1 > /dev/null

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

ibux 15th March 2007 09:56

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. 18th March 2007 19:11

Thank you

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

mackenga 23rd March 2007 00:12

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.

All times are GMT +2. The time now is 02:09.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.