0

This question already has an answer here:

Admin note: This question is different then why is sudo path different then su because the environmental variables in a bash script ran from cron do not appear to carry over from environmental variables set for either users as sudo or as su. (See everything after the BUT.)

When running sudo su and showing paths, I have /usr/local/bin in my path. I have several custom apps I put in that folder in the intent of making them available system wide. In etc/sudoers, /usr/local/bin is in the secure_path.

BUT

When running a bash script executed as root via a cron job, /usr/local/bin is apparently not preserved in the path as I get command not found when attempting to run apps that are installed there, despite the fact they are in /etc/sudoers.

How do I get these apps to be available to root?

Ubuntu 16.10

marked as duplicate by sam, jayhendren, terdon Dec 28 '16 at 23:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from meta.unix.stackexchange.com Dec 28 '16 at 22:33

This question came from our discussion, support, and feature requests site for users of Linux, FreeBSD and other Un*x-like operating systems.

2

The environment in a cron job is, as you are seeing, different from that in a shell invoked by su - or sudo -s or sudo /path/to/executable. You can, however, set variables within the cron table:

PATH="$PATH:/usr/local/bin"
0 0 * * * /path/to/run-me-at-midnight-with-path-changes.sh

Not the answer you're looking for? Browse other questions tagged or ask your own question.