Quote:
Originally Posted by bangsters
Hi.
I need to run a particlar file (file.php) every x hours or so. I have set it in cron using wget "wget -O /dev/null /home/user/file.php".
Is that the correct syntax? If I try to run that same synax directly in SSH I can an "Unsupported scheme" error. But if I run tha script in console using "php /home/user/file.php" it works and outputs the result in the console.
Which syntax should I use for the cronjob?
Thanks!
|
wget retrieves a file from the provided path, it doesn't run it, so it's the wrong approach. Why not use the same method that worked from the command line? But remember that, depending on how you set up the cron schedule, the task may run with root privileges.
One way to solve this problem is to (1) use an up-to-date distribution and version, and (2) place the following in a file with any name located under /etc/cron.d:
30 * * * * (user name) /usr/bin/php /path/to/php/file.php
This entry will cause "file.php" to run every hour on the half-hour. Make sure the PHP script doesn't produce any output requiring a terminal. Or you can trap its output:
30 * * * * (user name) /usr/bin/php /path/to/php/file.php > /dev/null 2>&1