Looks like a bug (or odd intended practice) in cron not honoring the PATH variable.

Eric Bullen barnabus.pinklehorn at gmail.com
Sun Jan 29 01:15:24 UTC 2012


Hi All,

I'm running the following:

FreeBSD x 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30 UTC
2012     root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

I couldn't figure out why SOME of root's cronjobs weren't running, and
others were. Here's my test crontab for root:


#
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/user/local/bin
#

* * * * *  env > /tmp/x 2>&1
* * * * *  curl > /tmp/y 2>&1

The 'curl' command resides in /usr/local/bin, and the output for /tmp/x,
and /tmp/y are as follows:

# tail -10 /tmp/x /tmp/y
==> /tmp/x <==
LOGNAME=root
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/user/local/bin
PWD=/
USER=root
HOME=/
SHELL=/bin/sh

==> /tmp/y <==
curl: not found

The man (man 5 crontab) page says the following, but it LOOKS like cron is
passing the environment to the command, but doesn't take the PATH env var
as defined at top.

"SHELL is set to /bin/sh, PATH is set to /usr/bin:/bin, and
LOGNAME and HOME are set from the /etc/passwd line of the crontab's
owner.  HOME, PATH and SHELL may be overridden by settings in the
crontab; LOGNAME may not."

Not expected behavior. Thoughts? Please don't say that I should use
absolute paths in my crontabs. I am well aware of the security implications.

Thanks in advance!

-Eric


More information about the freebsd-stable mailing list