HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   add cronjob to run a page on a website (http://www.howtoforge.com/forums/showthread.php?t=11389)

md@waw.co.uk 14th March 2007 20: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

Thanks

ibux 14th March 2007 21:10

Quote:

Originally Posted by md@waw.co.uk
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:
Code:

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

todgerme 14th March 2007 22:26

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

ibux 15th March 2007 08: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.

md@waw.co.uk 18th March 2007 18:11

Thanks
 
Thank you

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

mackenga 22nd March 2007 23: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 10:03.

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