On busy days,I'd like to run

$./configure && make && sudo make install && halt

on the night and go to bed,hoping the application would automatically installed.But what I see the next days is the screen where sudo ask me for the password.So how could I run sudo with password in one command line or is there any other method to do this?

link|improve this question

73% accept rate
feedback

5 Answers

up vote 16 down vote accepted

Yes, use the -S switch which reads the password from STDIN:

$echo <password> | sudo -S <command>

So for your case it would look like this:

$./configure && make && echo <password> | sudo -S make install && halt

of course, replace <password> with your password.

link|improve this answer
13  
Obviously, one would not want to run this if there is any danger of someone else seeing the password in the shell history. – Brett Daniel Nov 9 '09 at 3:16
looking for quick ways to run privileged commands on a remote host and this works thanks. – nelaar Sep 15 '11 at 11:08
feedback

You could also configure sudo with visudo to allow you user to use make as sudo without password.

User_Alias USERS = your_user
Cmnd_Alias CMDS = /usr/bin/make
USERS ALL = (ALL) NOPASSWD: CMDS
link|improve this answer
feedback

You could replace your command line with this:

$sudo su

$./configure && make && make install && halt

You will be prompted for your password immediately, then the rest of the commands will run as superuser.

link|improve this answer
4  
an alternate (and probably preferred) version of this: sudo sh -c "./configure && make && make install && halt" – quack quixote Nov 9 '09 at 3:51
feedback

Setting up sudo like that is dangerous if someone happened to see the fact that sudo requires no password on your account. Unless you know what you are doing, don't do that. I've had it happen at my local A+ Training program with my experimental computer one too many times... -_-

What John T. said sounds good though, except there still is the risk of finding the password in shell history. What CarlF said sounds better, but if one command fails, the computer will still be running with superuser privileges.

link|improve this answer
feedback

If you want to take more care, you could make a script, change the permissions of the file so only root can read and edit and then just run it.

Example:
1) Create a file:

gedit ~/.easy.install  

2) Paste this and save:

./configure && make && echo <password> | sudo -S make install && halt  

3) Make it executable:

sudo chmod +x ~/.easy.install  

4) Change the permissions of the file so only root can read and edit it:

sudo chmod 700 ~/.easy.install  

5) Run:

~/.easy.install  

Enjoy ;-)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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