Manoj Govindan
Manoj Govindan

Reputation: 74795

Fabric sudo() captures incorrect output when user initially enters wrong password

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?

Upvotes: 3

Views: 1050

Answers (1)

Morgan
Morgan

Reputation: 4131

I'd say that is possibly a bug to be reported, but you could look to this section for some different combinations to try.

Upvotes: 2

Related Questions