Consider the following sudo call using Fabric:
def ls():
output = sudo('ls /tmp/', user = 'someone', shell = True)
print "Output:", output
Execute this using fab and enter a wrong password the first time you are prompted by sudo. You’ll see an error message and sudo will ask you for your password again. Enter the correct password the second time. The session looks something like this:
$ fab ls
[user@server] Executing task 'ls'
[user@server] sudo: ls /tmp/
[user@server] out: sudo password:
[user@server] out: Sorry, try again.
[user@server] out: sudo password:
[user@server] out: hsperfdata_someone
Output: Sorry, try again.
Done.
Note how the value of output is the first message printed by sudo when the wrong password is entered (“Sorry, try again.”). It doesn’t contain the subsequent correct output (“hsperfdata_someone”).
Am I doing something wrong? Is there a better way to capture output correctly in such cases?
I’d say that is possibly a bug to be reported, but you could look to this section for some different combinations to try.