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.


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


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:

0 0 * * * /path/to/run-me-at-midnight-with-path-changes.sh
| improve this answer | |

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