Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Expect "lrange $argv 0 0"

0 views
Skip to first unread message

hardwi...@gmail.com

unread,
May 20, 2005, 9:31:57 AM5/20/05
to
Hello
I am trying to write a small script to log into a group of servers
and get some details. I have the basic script done. I know the line of
code I need to call a list is "set host [ lrange $argv 0 0 ]". I just
dont know how to make the list of hosts. Any thoughts?
Thanks
Barry


#!/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)

}
}

SM Ryan

unread,
May 20, 2005, 11:02:44 AM5/20/05
to
hardwi...@gmail.com wrote:
# Hello
# I am trying to write a small script to log into a group of servers
# and get some details. I have the basic script done. I know the line of
# code I need to call a list is "set host [ lrange $argv 0 0 ]". I just
# dont know how to make the list of hosts. Any thoughts?
# Thanks
# Barry
#
#
# #!/usr/bin/expect -f

# ##########################
# #
# #
# ##########################

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.

0 new messages