user1071914
user1071914

Reputation: 3403

Cron job mysteriously stopped running?

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?

Upvotes: 5

Views: 22168

Answers (3)

TheTechGuy
TheTechGuy

Reputation: 17354

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.

Upvotes: 0

user1071914
user1071914

Reputation: 3403

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

Upvotes: 10

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.

Upvotes: 4

Related Questions