Home > bash > bash – When cron fails

bash – When cron fails

Problem:
A cron job did not run.

A colleague of mine once said “cron never fails”. From what I have observed he was 99% right. One time a job did not run because the machine was off, the other time it did not run at the expected time because the system date had been reset. All other times cron has run when expected. The scripts to be run by cron though, have failed many times due to various reasons. Yesterday, I had some issues with a script and I am making a note of it here just to document my cron job issues.(Not including network issues)

Solution:
Usually when this happens you check the following.

1. Did the script run in the correct location?
Make sure to always change to the correct directory at the start of your script.

2. Does the script have execute permissions?
chmod +x script.sh

3. The script itself has errors. So log them.
./script.sh 2 > script.log. (ie redirect standard output to a log file.)

Advertisements
Categories: bash Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: