-2

I am creating bash scripts and placing them in bin to be executed as commands. I have had no problems until my most recent command. I am attempting to create a command to restart network-manager.

My code:

#!/bin/bash
sudo service network-manager restart

this runs fine is run as the root user. If I run it as a non-root sudoer, the command prompts for a password and then fails with the following response (the command i made is called resnet):

user2@pavilion: resnet
Failed to restart natwork-manager.service: Unit natwork-manager.service not found.

Any help appreciated.

  • 5
    The error doesn't match the text in the script. Does the script saved in the bin directory contain the exact command sudo service network-manager restart? Or does it have network-manager misspelled as natwork-manager, as in the message? I suspect that the file that root is running when you run sudo resnet (if that's how you're doing it) is different from the file your user runs when you run resnet, which is expected when your $PATH is not the same as secure_path in the sudoers file. This is all a guess though, and not even a specific one. Please edit with more details. – Eliah Kagan Jul 29 '19 at 1:30
2

Looks like a typo in service name "natwork-manager" instead of "network-manager"

 Unit natwork-manager.service not found
  • 1
    This doesn't quite explain why running the script as root works but running it as a non-root user does not. Still, this is likely the best answer that can be given until the OP provides more information. – Eliah Kagan Jul 29 '19 at 6:48

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