Quote:
Originally Posted by Braynid
Ok, it's done. I added the given line to /etc/sudoers and added 'sudo' to my script and its ok.
Thanks a log guys!
|
If you wrote "sudo" in the beginning of the command inside the script file, you're trying to run ping with sudo. Instead run
where scriptname is the script filename which includes the ping command (without sudo). Your sudoers file lets you run the script you wrote using sudo (i.e. with root privileges), and that script then runs ping. If you put sudo inside the script, you're running the script file as a normal user, which works of course if you have read and execute permissions, but then in the script you're actually trying to run ping using sudo, and There You Go - sudoers file only gives you sudo access to the script, not to ping.
Short version: either add ping to the sudoers file too (like the script), which I don't necessarily recommend, or remove "sudo" from inside your script and simply ask users to run the script like "sudo scriptname". Or:
Solution II: write another script, that has inside:
where
scriptname is the name of the script that's running ping (got that? sorry if that sounds difficult). Then add
scriptname to the sudoers file (you did that already, didn't you?). Now what you're doing is when you run the above script, it will call
scriptname (which runs ping) through sudo, and because sudoers permits that,
scriptname gets run with root privileges, and should be able to run ping too. Got it?
I haven't tested the above method myself, but there is one thing I'm concerned about. If you grant sudo access to a script file that users could edit, and then sudo would run the commands inside the script as root too, you might actually give the users a chance to obtain root privileges..that sounds a bit scary so I hope I'm wrong and everything I've written here is crap