I'm on Debian Lenny. Unfortunately, the factory sudo package is not including the -n option that ships with sudo version 1.7. I'd really like to have a way to specify "If sudo asks for a password, I prefer to fail immediately instead of hanging on a prompt". Will this alternative work?

echo "" | sudo -S -u lalala command 
link|improve this question
feedback

2 Answers

Your command will end up reading from standard input as well (as Chris Acheson). You'd better redirect standard input back from the terminal.

echo | sudo -S -u lalala sh -c 'command </dev/tty'
link|improve this answer
feedback

This will only work with certain commands. When it needs a password, sudo will fail as expected, in a somewhat ugly fashion. When it doesn't, however, the newline will be piped to the command that you're running with sudo.

cat works fine:

cacheson@segfault:~$ echo "" | sudo -S -u cacheson cat file.txt 
text file

vim does not:

cacheson@segfault:~$ echo "" | sudo -S -u cacheson vim file.txt 
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...

Vim: Finished.
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.