Enter the password for the sudo command in the command chain

On Linux, how can I enter a password for one of the commands in the command chain that requires sudo. One example that I can think of is that after doing a long compilation job I want to turn off the machine.

make ; sudo init 0 

I want the shutdown command to start only after the finish is complete, but I would like to enter the password immediately, because I will not be there when the first command is executed. In addition, I do not want to run make with superuser privileges. Therefore, switching to root and running commands is also out of the question.

Thank!

+3
source share
6 answers
sudo sh -c "su -c 'make' $USER && init 0"

Change your uid early and often. This is the way to Chicago!

+7
source

sudo -v, sudo - , x ( 5). , timestamp_timeout sudoers.

make && sudo init 0

, make .

+3

sudo?

make; echo 'password' | sudo -S init 0

+2

Expect .

HOW-TO : http://www.linux.com/archive/feed/56066

- /etc/sudoers sudo . , .

+1

Change the timeout for sudo to something long enough to cover your use, then run something like sudo echoauthentication, and then run other commands. Until the password timeout has been reached, it should be executed without a second request.

0
source

You can add this to your sudoers file

username ALL = NOPASSWD: /sbin/init

where username is the username you want to allow.

0
source

All Articles