Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am facing a weired problem. I wrote a bash script to get the status of an app. Script is running fine when i am executing it from shell but when I am trying to execute the same script from crontab its not working. Not sure what is happening here...

Both manual and cron are running from root account.

share|improve this question
Did you look at /var/log/crond ? – shaktale Dec 6 '10 at 16:10
up vote 3 down vote accepted

This is generally because cron does not enable the PATH the same way as the shell does. Try typing "echo $PATH" at a prompt. Take the resulting PATH string and add it to the top of crontab file as PATH= That will probably fix it.


share|improve this answer
Thanks Man! that worked. That did not came in my mind. I was trying to add more verbosity to the script to fix it. – Ramesh Kumar Dec 6 '10 at 14:38

Root is probably getting an e-mail message explaining the error. Check root's mail, or else set MAILTO to some other address at the top of the file.

In addition to the possibility of a different PATH, be aware that crontab has some slightly weird escaping rules. Particularly, % becomes newline, and characters after the first % become stdin to the command.

share|improve this answer

@mfarver already answered I just want to add:
Any script running at startup will no have the PATH env variable set. You will have to call all those commands you use with the full path unless you export PATH. Anytime you are creating one simply add export PATH=$PATH:/bin:/usr/bin:/usr/local/bin at the beginning and you should be fine. Of course if you need other folders in that path add them there. I didnt want to make this an answer since @mfarver has the correct one already but I didn't have enough points to simply add a comment :).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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