0

My script is under /u01/software/aditya/script/ directory. Name of script is myscript.sh. I am able to run this script and getting output too. I am trying to set a cronjob for this script at 6.30 daily morning. I am doing this as root user. I have done following steps but not getting output.

crontab -e
30 06 * * * sh /u01/software/aditya/script/myscript.sh >> /u01/software/aditya/hello.log
:wq

but not getting any update in hello.log file :( . please help….

4
  • Is the :wq really in your crontab? Try removing it... Commented Sep 17, 2012 at 5:47
  • I fixed the markdown. :wq is in the editor (vi, I guess). Commented Sep 17, 2012 at 6:00
  • I'll bet it's the same problem as stackoverflow.com/questions/12453432/… Commented Sep 17, 2012 at 6:02
  • @Adi I deleted my answer because I misunderstood the ":wq" part was illustrating what you are typing to vi, not input meant for vi sneaking into your crontab instead. Commented Sep 17, 2012 at 6:15

2 Answers 2

1

First check your cron log file which is usually in /var/log/syslog. There should be entries similar to

Sep 17 06:30:01 localhost CRON[17725]: (root) CMD (sh /u01/software/aditya/script/myscript.sh >> /u01/software/aditya/hello.log)

If not, your script has never been run. This could be due to a broken crontab file. You should make sure that this file always ends with a newline, better insert more than one at the end so that deleting one accidentally won't break the file.

If this line exists in the log file then your script has been run, but didn't generate any output. This can happen due to a different environment when being run via cron.

Also note that >> only redirects stdout, not stderr. If you want to redirect stderr too, then add 2>&1 at the end of the line.

Sign up to request clarification or add additional context in comments.

Comments

0

Normally this is caused by a PATH problem. There is a very good chance that myscript.sh calls a command that is not available in the PATH that cron runs with. Some options to fix this are:

  • Make sure that every command in myscript.sh is a full path-reference (tedious)
  • Add source ~/.bashrc to the top of myscript.sh
  • Add export PATH=$PATH:<colon delimited list of paths necessary for myscript.sh to run correctly>

Pick one of the above, or you could also choose one of the options here: Hourly cron job did not run

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.