"Andrew Falanga" <not_real@hp.com> wrote in message
news:441862a9$1@usenet01.boi.hp.com...
> Ben C wrote:
> > On 2006-03-15, Andrew Falanga <not_real@hp.com> wrote:
> >>Hello,
> >>...
> >>The script is, basically,
> >>
> >>#! /usr/bin/expect
> >>
> >>set host [lindex $argv 0]
> >>
> >>spawn ssh root@$host "cd logs; ls"
> >>
> >>expect {
> >> -re password { sleep 1; exp_send "password\r" }
> >>}
> >
> > Most hosts I've logged into put the "password" line with a capital P.
> > password doesn't match Password.
> >
> > Tip: expect -d is very useful for seeing why this kind of thing doesn't
> > work.
> >
> > Otherwise I think the script is OK.
>
> Ok, I'm going to paste in the result of using the -d option:
>
> expect version 5.40.0
> argv[0] = /usr/bin/expect argv[1] = -d argv[2] = ./exp.expect argv[3]
> = remtest1
> set argc 1
> set argv0 "./exp.expect"
> set argv "remtest1"
> executing commands from command file ./exp.expect
> spawn ssh root@remtest1 cd logs; ls
> parent: waiting for sync byte
> parent: telling child to go ahead
> parent: now unsynchronized from child
> spawn: returns {24283}
>
> expect: does "" (spawn_id exp4) match regular expression "password"? no
> root@remtest1's password:
> expect: does "root@remtest1's password: " (spawn_id exp4) match regular
> expression "password"? yes
> expect: set expect_out(0,string) "password"
> expect: set expect_out(spawn_id) "exp4"
> expect: set expect_out(buffer) "root@remtest1's password"
> send: sending "utah1\r" to { exp4 }
It is working. You sent the password and it returned whatever is next.
However, you do not have an "expect" statement after the send password.
ALWAYS have a send/expect pair. Otherwise it will timeout, and the default
value is 10 seconds. I suggest buying and reading "Exploring Expect" by Don
Libes. All questions are answered in the book. However, sometimes it takes
a bit of research and understanding to find the answer.
Received on Sun Apr 30 02:34:19 2006