Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want my user 'dave' to be able to run a bash script without entering a password, so the script can run with crontab? For all other activities I'd like this user to be required to enter a password (as default). I know this can be accomplished via visudo, but I'm unable to get it to work. Wrong syntax maybe?

My Visudo Entry:

dave    ALL=(ALL) ALL
dave    ALL=NOPASSWD: /home/dave/thescript.sh

This works in the command line, I can execute it without entering a password. But the cron is returning [sudo] password for dave:

My crontab for user 'dave' is:

0 * * * * /home/dave/thescript.sh

Many thanks,
Ross

share|improve this question
    
doesn't the crontab mention sudo? –  Gilles Aug 9 '10 at 10:15
    
@Gilles: The cron tab doesn't. But thescript.shcontains a line with sudo... –  Ross Aug 9 '10 at 10:17

2 Answers 2

The sudoers entry dave ALL=NOPASSWD: /home/dave/thescript.sh lets dave execute sudo /home/dave/thescript.sh without entering a password. It doesn't say anything about using sudo from that script; sudo doesn't care about what script, if any, invoked it.

If the whole script should run as root, then invoke it with sudo /home/dave/thescript.sh in the crontab. But then, why not simply put the script in root's crontab?

Otherwise, if the script contains a line sudo /path/to/mycommand arguments, then put dave ALL=NOPASSWD: /path/to/mycommand arguments in the sudoers file. This will apply no matter where dave runs mycommand from.

share|improve this answer

Your entry above allows dave to run /home/dave/thescript.sh via sudo without entering a password.

You are not however running thescript.sh via sudo.

You will have to add a similar entry for the command that the script is trying to run via sudo to your sudoers file e.g.

dave ALL=NOPASSWD: /path/to/special/command
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.