3

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 

2 Answers 2

2

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.
2

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'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .