1

I'm running RHEL and I'm trying to set up a cron job to run a shell script every 5 minutes.

Following the directions here: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-configuring-cron-jobs

I have service crond start and chkconfig crond on. Then I edited /etc/crontab and added:

*/5 * * * * my-user /path/to/shell.sh

I did a chmod +x shell.sh. And I made sure to add a new line character at the end.

I'm expecting it to run every 5 minutes but it never executes.

What am I doing wrong?

James White
  • 535
  • 10
  • 24
  • 1
    possible duplicate of [CronJob not running](http://stackoverflow.com/questions/22743548/cronjob-not-running) – Cfx Jan 17 '15 at 20:28
  • How did find out that it doesn't run? There are several definitions of it running. For example: the whole crontab may not be running at all. Or this specific cronjob may not be executed becuase of a syntax error. Or the file doesn't have the correct execution rights. Or the file itself contains errors. So what exactly did you find out so far? – vrijdenker Jan 17 '15 at 20:28
  • Ah @Cfx 's post links to an excellent answer indeed – vrijdenker Jan 17 '15 at 20:29

1 Answers1

2

Simply try to add the cronjob entry and check the script is working fine or not by taking the viewable output in the script.

echo "test time - $(date)" > script.sh
chmod +x script.sh
crontab -e

Then enter the cronjob as below,

*/5 * * * * sh /path/to/script.sh > /path/to/log.file

Check if the log is writing correctly. If its fine, better cross check the script that you are trying to execute via cron. Otherwise it will be a cron issue.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114