#!/usr/bin/expect -f
##########################
#
#
##########################
set host [ lrange $argv 0 0 ]
set filename [open /tmp/test.baz "a"]
spawn telnet $host
expect {
"login:" {
send "xxxxxx\r"
expect "*:"
send "xxxxxx\r"
expect "*:"
expect "*#"
send "who am i >> /tmp/uptime.baz\r"
expect "*#"
send "uptime >> /tmp/uptime.baz\r"
expect "*#"
send "cat /tmp/uptime.baz ; rm /tmp/uptime.baz\r"
sleep 1.0
expect "*#"
puts $filename $expect_out(buffer)
}
}
If argv is a list of hosts, you can use a foreach.
foreach host $argv {
set filename [open /tmp/test.baz "a"]
spawn telnet $host
expect {
# "login:" {
# send "xxxxxx\r"
# expect "*:"
# send "xxxxxx\r"
# expect "*:"
# expect "*#"
# send "who am i >> /tmp/uptime.baz\r"
# expect "*#"
# send "uptime >> /tmp/uptime.baz\r"
# expect "*#"
# send "cat /tmp/uptime.baz ; rm /tmp/uptime.baz\r"
# sleep 1.0
# expect "*#"
# puts $filename $expect_out(buffer)
#
# }
# }
expect eof
}
#
#
#
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Title does not dictate behaviour.