0

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.

2

3 Answers 3

3

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.

Mark

1
  • Thanks Man! that worked. That did not came in my mind. I was trying to add more verbosity to the script to fix it. Dec 6, 2010 at 14:38
1

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.

0

@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 :).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .