Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I’m have a bash script that I run in /etc/crontab on Linux

$ uname -a
Linux mymachine.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The bash script contains a line

sudo shutdown -r 5

However, when the cron job runs (as a user named “myuser”), the machine is never rebooted and I instead find this in the logs

[sudo] password for myuser:

What do I need to do to give this user the ability to reboot from cron? It’s not an option to run this script as another user.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You need a line in /etc/sudoers that reads:

myuser ALL = NOPASSWD:  /sbin/shutdown

The NOPASSWD part tells sudo to let myuser run the shutdown command with providing a password.

To add such a line to /etc/sudoers, run (as root):

sudoedit /etc/sudoers

sudoedit will scan your updated version of the file for errors before installing it. Consequently, this is safer than editing the file directly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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