linux - How to automate telnet session using Expect? -
i'm trying write expect script automate telnet. have far.
#!/usr/bin/expect # test expect script telnet. spawn telnet 10.62.136.252 expect "foobox login:" send "foo1\r" expect "password:" send "foo2\r" send "echo hello world\r" # end of expect script. basically, want telnet following ip address , echo hello world. however, seems script fails after attempting telnet...i'm not sure if it's able accept login , password input, not echoing hello world. instead, output:
cheungj@sfgpws30:~/justin> ./hpuxrama spawn telnet 10.62.136.252 trying 10.62.136.252... connected 10.62.136.252. escape character '^]'. welcome opensuse 11.1 - kernel 2.6.27.7-9-pae (7). foobox login: foo1 password: foo2~/justin>
you're sending echo command without first expecting prompt. try:
# after sending password expect -re "> ?$" send "echo hello world\r" expect eof
Comments
Post a Comment