To view parent comment, click here.
To read all comments associated with this story, please click here.
If someone kills your script (I checked, they can) midway through execution, won't the system be left with sudo set to 'nopasswd'?
Anyway, if your script requires the user to give a password for sudo the first time (when the command setting to NOPASSWD is run), why not just have THEM run your script as sudo, and run everything assuming you're root?
I didn't test it, but I'm pretty sure sudo would be inherited by all processes spawned by your script, so you wouldn't have to worry about sudo timing out and sitting at a prompt until someone notices. Correct me if I'm wrong.
I mean, yes this would cause problems if the user forgot to run the script as 'sudo', but you could check that quickly by trying to create (and then remove) a file in, say, /etc; if that fails you exit with an error saying the script must be run with sudo.
I would also log completion messages AFTER you've successfully changed the setting. I'm assuming that the logging command is less likely to fail than the configuring command...






Member since:
2005-11-05
1. You're an idiot, because no it doesn't. Check your f--king code.
Before you make yourself look more ignorant than you have ALREADY PROVEN, take a look at line 120. If you are blind, it states this:
sudo sed -ie '/NOPASSWD/s/NOPASSWD: //' /etc/sudoers
For those of you that don't understand this, this takes the NOPASSWD statement and replaces it entirely with null. No, I didn't all of the sudden change the file on my site because of your statements...
2. You're an idiot because it wouldn't even be necessary. Once you initiate the first /bin/sh using sudo scriptname everything spawned from that shell, ie. the remainder of the script, runs as root.
This wasn't supposed to be run with sudo. The script runs sudo by itsself. Being an elitest prick doesn't help anything or anyone.
Notice by reading my response to #1 that you were indeed wrong. You were wrong, and that is a fact. End of story.