Sudo in shell script
Hi guyz,
Whats wrong with this line? Code:
sudo -u user /usr/bin/nohup sh /home/user/somescript.sh & |
You should not put the '&' at the end of the line, because the whole "line" goes in background and sudo can't ask you the password.
Put the '&' inside the script "somescript.sh", instead. So that first sudo asks for the password (in foreground), and only then the script goes in background. |
Quote:
Code:
sudo -u user sh -c '/usr/bin/nohup /home/user/somescript.sh &' |
Thanks that worked for me...
|
Can this be used to run a script that will work as "superuser"?
for example: set an icon on the users desktop to run a script such as:
nohup ~/trial.sh & that script calls this one: sudo -u (username) cp /etc/my-resolv.conf /etc/resolv.conf To replace the domain name servers with your own choice. What have I got wrong in this? I used to write some 'bat' files in DOS, but this ain't DOS. |
try this
Quote:
|
sudo -u username 'cp /etc/my-resolv.conf /etc/resolv.conf'
I get the error: " sudo -u username 'cp /etc/my-resolv.conf /etc/resolv.conf' " But your note did prod me into tring several other options. I want this to work under the gksu oprion,so I won't have to go through the routine of calling up a terminal and typing into it. I'd prefer just to have it work from clicking an idon on the desktop. Tis is what finaly works for me: I put an icon on the panel, and this line in the command portion: " gksu cp /etc/resolv.conf /etc/m-resolv.conf " That worked! Thanks for the prod. Now, I'll just have to modify that command to copy from m-resolv.conf to resolve.conf instead of the way it now does. Dave |
@littlejoe5
To run a script as root from a script running as a user using sudo without a password: visudo and add a line at the bottom: user ALL=(root) NOPASSWD: /path/to/root/script.sh Then inside the user script: sudo /path/to/root/script.sh Only "user" can run script.sh without a password with sudo. This effectively gets around Linux's ban on SUID root for scripts. Russ |
Thanks rustec. I didn't know that tool existed. Looks like a pretty powerful tool - and maybe dangerous. I'll have to study it.
Dave |
All times are GMT -5. The time now is 12:47 PM. |