5

I have a cron job on an Ubuntu 10.4 server that stopped running for no apparent reason. (The job ran for months and has not been changed.) I am not a *nix guru so I plead ignorance if this is a simple problem. I can't find any reason or indication why this job would have stopped. I've restarted the server without success. Here's the job:

# m h  dom mon dow   command
0 * * * * java -jar /home/mydir/myjar.jar >>/home/mydir/crontaboutput.txt

The last line in the output file shows that the program ran on 8/29/2012. Nothing after that.

Any ideas where to look?

2
  • 2
    There should be something in your system log when the job was run. The other thing you could try is to add 2>&1 to the job to see any errors in your text file. Nov 8, 2012 at 22:07
  • Or perhaps your crond has stopped, or changed configuration. Nov 9, 2012 at 8:19

3 Answers 3

10

There should be something in your system log when the job was run. The other thing you could >try is to add 2>&1 to the job to see any errors in your text file. – Lars Kotthoff yesterday

This proved to be the key piece of information - adding 2>&1 allowed me to capture an error that wasn't getting reported anywhere else. The completed command line then looked like:

java -jar /home/mydir/myjar.jar  2>&1  >>/home/mydir/crontaboutput.txt
4

Perhaps your cron daemon has stopped, or changed configuration (i.e. /etc/cron.deny). I suggest to make a shell script, and running it from crontab. I also suggest to run thru your crontab some other program (just for testing) at some other time. You can use the logger command in your shell script for syslog. Look into system log files.

0

Accepted answer is correct, (i.e, check the error logs) which pointed out the error in my case. Besides check for the following issues

  1. include('../my_dir/my_file.php) may work from url but it will not work when cron job is run, will spit out error.

  2. $_SERVER variables does not work inside cron os if you are using $_SERVER['DOCUMENT_ROOT'], it will not be recognized and you will have an error in the cron job.

Make sure to test the cron and have it run, send an email etc to make sure it is run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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