> I have just set up a Crontab, using Putty. I want it to run test.php, > which I have located, for the sake of this test, at > mydomain.com/test.php. > > Running via http://mydomain.com/test.php works ok. But the cron job > isn't working, and isn't reporting. > > 1) Can cron run a php file? I thought that I had done that before. > > 2) Where does the cron report email go to? I putty'd in as admin, and I > have set up and tested mail at [EMAIL PROTECTED] > > > > This is my Putty login script... > login as: admin > Sent username "admin" > [EMAIL PROTECTED]'s password: > [EMAIL PROTECTED] crontab -l > 00,10,20,30,40,50 * * * * /home/e/l/mydomain/public_html/cron.php > > > cd /home/e/l/eleganthomes/public_html takes me to the correct folder... > > Any suggestions? > > -- > Pete Clark
There are several ways to approach this, depending on what resources you have on the server. If your page really only works in the context of a web browser, you may want to use a text-based web browser such as lynx or links to run your script. In this case you would specify the URL to your page, not the path to the file in the filesystem. I normally use lynx: lynx --dump http://www.server.com/dir/script.php 2&> /dev/null The 2&> /dev/null will send all output, including errors, to the trash. Otherwise, output would be sent as an email to an address you specify or the default user running the cron job. IMPORTANT: Your PHP script will run as the web server user with this technique. _____ You could create a script with the usual <?php ... ?> PHP tags and add a line at the very top which specifies the location of the command-line PHP interpreter. Normally this looks like: #!/usr/bin/php It must be on the first line and the pound sign (#) must be the firs character for this to work. For this to run, you must also make the script executable with a chmod command (chmod 755 script.php) or a similar feature of your FTP program. IMPORTANT: In this case, the PHP script will run as the user who runs the cron job. This may be a problem if you have to have write access to certain files and directories. _____ Another way, if you have the PHP command-line interpreter (whereis php) is to use it to launch an ordinary PHP script. (It does not have to be made executable and there are some good reasons not to do so.): /usr/bin/php /path/to/script.php IMPORTANT: In this case, the PHP script will run as the user who runs the cron job. Same caveat above applies. _____ With respect to your minute specification, as indicated in the man page for crontab (man 5 crontab) you can use the asterisk slash notation to get multiple values for a given parameter. In your case, you want it to run every 10 minutes: 00,10,20,30,40,50 * * * * /home/e/l/mydomain/public_html/cron.php becomes: */10 * * * * /home/e/l/mydomain/public_html/cron.php Note that the slash does not mean division in this case. It is the period of time between repetitions. As such */6 would be every six minutes. It takes some getting used to. _____ Keep in mind that many environmental variables will change if you start running a PHP program as a shell script (example 2) or run it from the command-line interpreter (example 3). Test carefully to make sure things are working as desired for your script. James _____ James D. Keeline http://www.Keeline.com http://www.Keeline.com/articles http://Stratemeyer.org http://www.Keeline.com/TSCollection http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc. Summer Semester Begins Jun 20 -- New Classes Start Every Few Weeks. Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
