On a new Ubuntu install, a user's PATH
is:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
But in that same user's cron environment, it is:
/usr/bin:/bin
I looked at all the user's dot files in the home directory, nothing in there is changing the PATH
.
What's changing the PATH
? Why doesn't cron use that PATH
?
Cron does not execute processes in a login shell. Because of this, all the typical scripts are not sourced when a process is executed.
Executing the process from within a login shell should replicate the user's environment.
Put something like this in a crontab and compare the two outputs:
As you can see,
/tmp/bashenv
will have a whole slew of environment variables that/tmp/env
does not. This is becauseenv
was invoked in a login shell usingbash -l
.Regarding the question - why is this so - the manual page that explains it is
crontab(5)
, IOW the one accessible throughman 5 crontab
(not the default one in section 1). The cron daemon does not try to emulate a shell session, rather it sets up a clean, minimal environment for the cron jobs to run in, and then in turn allows the crontab file to set its own arbitrary environment variables. The newer cron daemon shipped with Debian also has several additional provisions forpam_env
etc.