crontab execution doesn't have the same environment variables as executing user
Cron always runs with a mostly empty environment.
SHELL are set; and a very limited
PATH. It is therefore advisable to use complete paths to executables, and export any variables you need in your script when using
There are several approaches you can use to set your environment variables in
cron, but they all amount to setting it in your script.
Set each variable you need manually in your script.
Source your profile:
. $HOME/.bash_profile (or
(You will usually find that the above file will source other files (e.g.
/etc/profile.d/*) - if not, you can source those as well.)
Save your environment variables to a file (run as the desired user):
env > /path/to/my_env.sh
Then import via your cron script:
env - `cat /path/to/my_env.sh` /bin/sh
In some cases, you can set global
cron variables in
/etc/default/cron. There is an element of risk to this however, as these will be set for all