Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a file called svrestart in /home/gab/bin (which is a folder that should be automatically be added to path on startup) which contains:

/etc/init.d/nginx restart
/etc/init.d/php5-fpm restart

Then I did chmod +x svrestart and then I rebooted.

Now if I run svrestart I get a permission denied error because I can't have access to these services. If I run sudo svrestart, on the other hand, I get:

sudo: svrestart: command not found

Because the command is hosted in /home/gab/bin and the root user probably can't find it.

How do I make this work?

share|improve this question
up vote 3 down vote accepted

Just change these lines accordingly.

sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart

You will be prompted for the sudo password for the first command.

share|improve this answer
    
... unless he's a sudoer without password. – Daniel Beck Dec 30 '11 at 10:11
    
@DanielBeck Isn't there a difference between GNU sudo and the one on OS X here? What's to do in this case, actually? – slhck Dec 30 '11 at 10:21
    
Run less /etc/sudoers and look for %wheel, the traditional Unix (?) admin group. There is one line requiring a password, another not requiring it. %admin, the OS X group used instead, also requires a password. Edit the file (as root of course), add NOPASSWD in the %admin line, sudo -k to invalidate your sudo timestamp (so you'd need to enter your password again even though you entered it only a short time ago), and sudo ls. No password required. – Daniel Beck Dec 30 '11 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .