Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do you include the root password, say for shutting down an ubuntu machine?

like,

sudo shutdown now

is it possible to include the password on this 1 line? like an extra parameter?

reason for this is I am trying to play with this app named azr remote prompt which lets you send commands from your blackberry to your ubuntu machine and it seems like a 1 way trip. you send commands, but you don't get any response from the computer.

share|improve this question
3  
You can also edit /etc/sudoers to allow some commands to not need a password. –  richard May 14 '12 at 11:48
    
@richard if he was able to edit the /etc/sudoers he wouldn't ask this question! Here's a way: sleekmason.wordpress.com/fluxbox/… –  Adit Saxena Apr 25 at 8:09
    
@AditSaxena, to answer your comment: because I just added a comment, it could lead to an answer, but is not an answer. –  richard Apr 30 at 19:37

1 Answer 1

up vote 15 down vote accepted

Yes, sudo has a '-S' a switch that allows it to read in the sudo password from stdin. All you have to do is echo your root password - so for your instance it would look like this (replace [PASSWORD] with your root password)

history -d $((HISTCMD-1)) && echo '[PASSWORD]' | sudo -S shutdown now
share|improve this answer
    
hi man, thanks for the answer. :D –  simon May 14 '12 at 6:51
9  
@simon: This will make the password appear in the shell history file, which is not recommended! I suggest you put history -d $((HISTCMD-1)) && before that code, to ensure that line doesn't appear in the history file. So, the final command should be history -d $((HISTCMD-1)) && echo '[PASSWORD]' | sudo -S shutdown now. –  André Paramés May 14 '12 at 8:46
2  
If you're using Bash, you can also prevent writing history by setting an empty HISTFILE as in HISTFILE=; command here.... –  Lekensteyn May 14 '12 at 11:27
    
@AndréParamés yeah man thanks for the additional information, but I think I won't be using it for now because after running the command on my phone the executed commands get erased right away but anyway thanks again, will be keeping that in mind in case it might be necessary in the future –  simon May 15 '12 at 11:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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