Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running a simple shell script that runs just fine in a login shell from cron, where it doesn't run. For some reason, /usr/local/bin is not on the users path when run from cron while it is when run in a shell.

Where is the environment for cron determined?

share|improve this question

2 Answers 2

Generally, from the non-login environment established for /bin/sh, which is the default used to run the command.

You can set additional environment variables in your crontab in most versions, vis:

PATH=/usr/local/bin:/usr/bin:/bin
@reboot whatever

Check crontab(5) for details; man 5 crontab

share|improve this answer

Check which shell your script is using.

The shell and variables for crontab are specified in /etc/crontab

x@x:~$ cat /etc/crontab 

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

The profile file used by sh is in user home.

x@x:~$ ls ~/.profile 
/home/x/.profile

You can add PATH variable in end of this file (Make sure you are adding in profile file of correct user)

PATH="$PATH:/usr/local/bin"

or you can add the same line in your own script.

share|improve this answer

Your Answer

 
discard

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.