0

root's default PATH is

$ sudo su
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

After creating /etc/cron.d/myjob

35 * * * * tim ( date && echo $PATH && date ) > /tmp/cron.log 2>&1

/tmp/cron.log shows the default value of PATH is:

/usr/bin:/bin

Is the default PATH value in a crontab file not the one for the root? Why?

Whose PATH value is it?

WIll the default PATH value be different if I add the job in /etc/crontab or a file under /etc/cronb.d/?

Does it matter which user is specified in the cron job? (such as tim in the above example)

Thanks.

Tim
  • 101,790

2 Answers2

5

This depends on the version of cron you’re using. I seem to remember you use Debian; cron there sets a number of variables up as follows:

Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab’s owner. PATH is set to "/usr/bin:/bin". HOME, SHELL, and PATH may be overridden by settings in the crontab; LOGNAME is the user that the job is running from, and may not be changed.

(See the crontab manpage for details.)

Stephen Kitt
  • 434,908
  • in Ubuntu 18.04 the default PATH is /usr/bin:/bin , and in Ubuntu 22.04 the default PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin , quite the mouthful! (even for users other than root. that was unexpected! it's a sudo group member though..) – hanshenrik May 22 '23 at 06:38
2

Since you don't mention a specific cron implementation, let me assume that you are talking about the original UNIX cron implementation.

There is a default PATH for root (which is /usr/sbin:/usr/bin) and another for non-root users (which is /usr/bin:).

The related values may be overwritten by entries like:

PATH=
SUPATH=

in the file /etc/default/cron.

See: https://sourceforge.net/p/schillix-on/schillix-on/ci/default/tree/usr/src/cmd/cron/

See also: http://schillix.sourceforge.net/man/man1m/cron.1m.html and http://schillix.sourceforge.net/man/man1/crontab.1.html

If you refer to a clone implementation, you should mention which implementation you have in mind...

schily
  • 19,173