2

I've tried reading up on this, but I can't figure out why it's happening.

When Expect sends the password it appears as echoed cleartext in the terminal and afterwards "Sorry, try again." appears.

The script goes as follows

#!/usr/bin/expect -f

spawn bash
send -- "sudo (many tasks)\r"
expect -exact "\[sudo\] password for elade: "
send -- "password\r"
expect -exact "user@x.x.x.x's password: "
send -- "password\r"
expect "@"
send -- "echo Done; sleep 1; exit\r"
expect eof

The terminal output after sending first password is:

[sudo] password for elade:
password
Sorry, try again.

I'm using Arch linux and the terminal emulator Konsole.

closed as off-topic by Jeff Schaller, Rui F Ribeiro, DarkHeart, ilkkachu, Archemar Apr 24 '17 at 9:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, Rui F Ribeiro, DarkHeart, ilkkachu, Archemar
If this question can be reworded to fit the rules in the help center, please edit the question.

  • try a small delay between the expect and sending the password. – Robert Jacobs Apr 17 '17 at 15:13
  • 1 sec, still the same. Tnx anyway – E. l4d3 Apr 17 '17 at 15:21
  • Try replacing the sudo command with od -c. See exactly what is being sent by your script to sudo. – Robert Jacobs Apr 17 '17 at 15:42
  • When generating using autoexpect, the script halts and does nothing after the first sudo command is run. And if replaced sudo with od -c the output says that the following command is No such file or directory. – E. l4d3 Apr 17 '17 at 16:52
  • Append: I looked at the auto-generated script and added \r where the script halted. After that, the same thing happens. Password showing in terminal output and that it is wrong. – E. l4d3 Apr 17 '17 at 16:59
2

Thanks for all the input above. After trying all the suggestions, the original script suddenly just started working again. When prompted for password, and the password got sent by expect, it did not appear in the terminal as before and was rejected, it was passed invisibly to the terminal and accepted, as if I was typing myself.

So I ran the script a few times and 1/10 times the same problem still persisted. There are three different passwords that needs to be sent, and which one "passes" and which one gets "echoed" in the terminal and rejected seems random. I don't why this is happening, but I suspect it has little to do with Expect and the actual script.

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