
Why does cron silently fail to run sudo stuff in my script? - mindcrime
https://unix.stackexchange.com/questions/49077/why-does-cron-silently-fail-to-run-sudo-stuff-in-my-script
======
simonblack
Why use sudo with cron in the first place? Sudo is very restrictive in its
action, especially in scripts. If you must use sudo with a script, run the
whole script under sudo rather than have sudo acting on individual commands
within the script.

Another thing to watch with cron is that its environment is NOT the same as
running a script from your CLI, unless you specifically set those environment
variables in your crontab.

Give root a password like it should have, and run administrative privileged
cron jobs from a root crontab.

~~~
mindcrime
_Another thing to watch with cron is that its environment is NOT the same as
running a script from your CLI, unless you specifically set those environment
variables in your crontab._

Yep. This is one big reason so many scripts work fine from the CLI, then fail
when run under cron. I've been bitten by that before.

For me, the script I was just working on was prototyped from the command line,
logged in as a regular user. It wound up using sudo and running under the user
crontab, and then ran into this very problem. It's not something I consider
important enough to change, but you have a good point. It would be cleaner to
just run it under the root crontab in the first place.

