Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect 1

Status
Not open for further replies.
Jul 31, 2001
37
0
0
US
Hello all,
Can anyone tell me how to pass multiple arguments in an expect script. I can't seem to get more than one to work. Below is my test script this script will spawn a telnet session connect to a router then kick back the output for a show interface command. right now the only variable that you see is the interfae name. i'd like to pass the ip address first then the interface name as variable 1 and variable 2.
Thanks in advance.
Mark


#!/usr/bin/expect --

log_user 0
set timeout 60
spawn telnet 192.168.1.1
expect "Username:"
send "routeradmin\r"
expect "Password:"
send "password\r"
expect "core-router#"
log_user 1
send "show int $argv \r"
expect "core-router#"
log_user 0
send "exit\r"
send_user "\n"
 
#!/usr/bin/expect --

set TEST1 [ lindex $argv 0 ]
set TEST2 [ lindex $argv 1 ]
set TEST3 [ lindex $argv 2 ]
etc., etc.

log_user 0
set timeout 60
spawn telnet 192.168.1.1
expect "Username:"
send "routeradmin\r"
expect "Password:"
send "password\r"
expect "core-router#"
log_user 1
send "show int $TEST1 \r"
expect "core-router#"
send "show int $TEST2 \r"
expect "core-router#"
send "show int $TEST3 \r"
expect "core-router#"
etc., etc.
log_user 0
send "exit\r"
send_user "\n"
 
pmcmicha,
Totally appreciate your help. Could i do something like this? It doesn't seem to work for me. the firs variable i want to pass is the ip address of the host the second is the interface name as shown below. Thanks again for the help
Mark



#!/usr/bin/expect --

set TEST1 [ lindex $argv 0 ]
set TEST2 [ lindex $argv 1 ]

log_user 0
set timeout 60
spawn telnet $TEST1
expect "Username:"
send "routeradmin\r"
expect "Password:"
send "password\r"
expect "core-router#"
log_user 1
send "show int $TEST2 \r"
expect "core-router#"
log_user 0
send "exit\r"
send_user "\n"
 
Strike that it worked as it should have when i corrected a typo. Really appreciate the help. let me know if you need any router help thats what i am good at. Thanks again

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top