Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  84] [ 0]  / answers: 1 / hits: 683606  / 3 Years ago, tue, november 9, 2021, 9:30:19

I want to verify if a certain crontab works properly. I have added a job like this:



  */2 * * * * /path_to_my_php_script/info.php >/dev/null 2>&1


I know that i redirect to the null device, but i not sure if the above command is good.



*Edit 1: In my /var/log/syslog every two minutes i have the following error:



 (CRON) error (grandchild #2788 failed with exit status 2)


*Edit 2: No errors in logs with this new job:



 */2 * * * * /usr/bin/php /path_to_my_php_script/info.php >/dev/null 2>&1

More From » cron

 Answers
0

The syntax for the crontab entry looks correct. Indeed, if you edit your crontab using "crontab -e" (as you should), you'll get an error if you specify a syntactically invalid crontab entry anyway.




  1. Firstly, does /path_to_my_php_script/info.php run correctly from the command-line?


  2. If so, does it also run correctly like this?:



    /bin/sh -c "(export PATH=/usr/bin:/bin; /path_to_my_php_script/info.php </dev/null)"

  3. If that works, does it work like this?



    /bin/sh -c "(export PATH=/usr/bin:/bin; /path_to_my_php_script/info.php </dev/null >/dev/null 2>&1)"



Step (3) is similar to how cron will run your program (as documented in "man 5 cron".



The most likely problem you're having is that the PATH cron is using to run your program is too restrictive. Therefore, you may wish to add something like the following to the top of your crontab entry (you'll need to add in whatever directories your script will need):



PATH=~/bin:/usr/bin/:/bin


Also note that cron will by default use /bin/sh, not bash. If you need bash, also add this to the start of your crontab file:



SHELL=/bin/bash


Note that both those changes will affect all the crontab entries. If you just want to modify these values for your info.php program, you could do something like this:



*/2 * * * * /bin/bash -c ". ~/.bashrc; /path_to_my_php_script/info.php"


It's also worth mentioning that on a system configured for "mail" (in other words a system which has an MTA configured [sendmail/postfix/etc]), all output from crontab programs is sent to you via email automatically. A default Ubuntu desktop system won't have local mail configured, but if you're working on a server you can just type "mail" in a terminal to see all those cron mails. This also applies to the "at" command.


[#41615] Wednesday, November 10, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itutejagua

Total Points: 89
Total Questions: 124
Total Answers: 113

Location: British Indian Ocean Territory
Member since Sun, Feb 13, 2022
2 Years ago
;