0

I have a script written which works perfect on terminal however gives error when called through crontab. It took me a while that the problem is with the cron environment not my script.

so I tried few options after reading various posts online:

* * * * * PATH=/home/sam/bin:/home/sam/scriptbin/ /path/to/script Didn't work

* * * * * bash -lc /path/to/script Didn't work

* * * * * /path/to/script Didn't work

`PATH=blahdeblah
* * * * * jobdejob` Didn't work

How can I change $PATH variable for crontab in OPENSUSE or include in cron file so that it works. I am using open suse 11.

Thanks!

0

Two ways; first, some cron daemons allow environment variables to be set:

PATH=blahdeblah
* * * * * jobdejob

Second, use the env(1) utility, which then runs the actual job:

* * * * * env PATH=blahdeblah jobdejob

Three! Use fully qualified paths in the cron jobs. No, no, four ways, as Jeff says, set the path in the script:

#!/bin/sh
PATH=blahdeblah
...

Fifth, a ruthless devotion to the PATH.

  • can you share more on env(1).. no idea what is that? – learnningprogramming Feb 4 '16 at 21:14
  • Or for better locality, set the PATH you need at the top of your script. – Jeff Schaller Feb 4 '16 at 21:35
  • I second @JeffSchaller's idea instead of making life harder for yourself, trying to figure out how your cron daemon will react – MelBurslan Feb 4 '16 at 21:53
  • neither of the above two options seems to work.. – learnningprogramming Feb 4 '16 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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