I have Ubuntu 9.10 (and cannot change it in the near future due to testing) with expect5.45. Expect is working, but I have (at least) two issues. The first is that expect does not seem to be matching the string "password:". On my machine, the manual interaction appears as below:
root@Monkey2:~# rlogin $remoteAddress -l root
[email protected]'s password:
Linux systest-desktop 2.6.31-22-generic #70-Ubuntu SMP Wed Dec 1 23:51:13 UTC 2010 i686
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
72 packages can be updated.
70 updates are security updates.
Last login: Mon Jun 20 13:40:22 2011 from monkey2.local
root@systest-desktop:~#
The contents of the script is as follows:
#!/usr/local/bin/expect -f ## Connect to a neighboring linux box. spawn ssh nn.nn.nnn.nnn -l root expect "password:\n" send "mypassword\n" send "$expect_out(0,string)"
The script gets and displays the line requesting the password but times out. I've tried using "password:", "password: ", "password:\r" and password:*" but none seem to match.
The second issue is that the expect_out variable is not recognized and I get the following error when I run the script (whose name is 'this' and only has 11 lines!):
can't read "expect_out(0,string)": no such variable while executing "send "$expect_out(0,string)"" (file "this" line 18)
First thing to do when debugging expect programs is to add this line near the top:
exp_internal 1
That turns on (verbose) debugging output that shows what expect has seen from the spawned program, and how it matches your expect patterns.
Typically, one does something like this:
expect -re {password: $}
send -- "the_password\r"
You need to send a \r
(a carriage return) instead of \n
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With