Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
share|improve this question
    
unfortunately all above tried but does not work for me. as you say the trial /bin/sh -c "(export PATH=/bin; /tmp/trial.sh </dev/null)" shows below message, not sure what it is /bin/sh: PATH=/bin: is not an identifier –  luckbychance May 23 at 11:03

4 Answers 4

up vote 10 down vote accepted

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:

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.

share|improve this answer

You can see your active cron with the terminal command:

crontab -l

Here are the parameters in order:

1) min (0 - 59)

2) hour (0 - 23)

3) day of month (1 - 31)

4) month (1 - 12)

5) day of week (0 - 6) (Sunday=0)

6) command

So, you are calling your script every first minute of each hour. You should test your output at a more often interval for testing purpose:

* * * * * <command> #Runs every minute

This will call it every minute!

share|improve this answer
    
*/2 * * * * i have changed to every two minutes now –  saveandload.com Dec 6 '11 at 10:15

Do not redirect error output to /dev/null and grep /var/log/syslog for cron output.

grep cron /var/log/syslog
share|improve this answer

ah !!

got the answer myself, I checked and did not find crond inside the default installation directory i.e /etc/init.d/

will now try and reply.

note -- I did check the cron.allow, cron.deny too. All is fine so far.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.