Answer the question
In order to leave comments, you need to log in
How to monitor the result of executing commands in a telnet session launched via expect?
I'm trying to automate the collection of some data from nodes accessible via telnet using a script using expect
#!/usr/bin/expect
set timeout 20
set name [lindex $argv 0]
log_user 1
spawn telnet $name
expect "login:"
send "USERNAME"
expect "Password:"
send "PASSWORD"
send " "
send "show ip interface eth0 brief"
send " "
send "exit"
Trying 10.10.10.5...
Connected to 10.10.10.5.
Escape character is '^]'.
CLI interface
login:
Password:
Trying 10.10.10.5...
Connected to 10.10.10.5.
Escape character is '^]'.
CLI interface
login: USERNAME
Password: ********
nodename>
nodename>show ip interface eth0 brief
Interface IP-Address Status Protocol
eth0 10.10.10.5 up up
nodename>
nodename>exit
Connection closed by foreign host.
Interface IP-Address Status Protocol
eth0 10.10.10.5 up up
Answer the question
In order to leave comments, you need to log in
Good afternoon,
I did it like this:
output=$(expect -c '
spawn telnet 10.250.0.'$Counter'
expect "User name:"
send "admin\r"
expect "Password:"
......
send "cable-diagnostics '$I'\r"
expect "%"
......
echo "$output"
It seems necessary to add \r and expect "%"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question