I have a script run from a non-privaleged users' crontab that invokes some commands using
sudo. Except it doesn't. The script runs fine but the sudo'ed commands silently fail.
The script runs perfectly from a shell as the user in question.
Sudo does not require a password. The user in question has
(root) NOPASSWD: ALLaccess granted in
Cron is running and executing the script. Adding a simple
date > /tmp/logproduces output at the right time.
It's not a permissions problem. Again the script does get executed, just not the sudo'ed commands.
It's not a path problem. Running
envfrom inside the script being run shows the correct
$PATHvariable that includes the path to sudo. Running it using a full path doesn't help. The command being executed is being given the full path name.
Trying to capture the output of the sudo command including STDERR doesn't show anything useful. Adding
sudo echo test 2>&1 > /tmp/logto the script produces a blank log.
The sudo binary itself executes fine and recognizes that it has permissions even when run from cron inside the script. Adding
sudo -l > /tmp/logto the script produces the output:
User ec2-user may run the following commands on this host:
(root) NOPASSWD: ALL
Examining the exit code of the command using
$? shows it is returning an error (exit code:
1), but no error seems to be produced. A command as simple as
/usr/bin/sudo /bin/echo test returns the same error code.
What else could be going on?
This is a recently created virtual machine running the latest Amazon Linux AMI. The crontab belongs to the user
ec2-user and the sudoers file is the distribution default.