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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Expect with a list of commands

Status
Not open for further replies.

numele

ISP
Apr 8, 2010
2
US
I am having issues with an expect script used in a bash script. How it functions is my bash script receives form post data with a list of commands and a list of routers to process the commands on and the lists are sent to variables. The expect script telnets to each router on the list and pushes the commands and it works. My problem is when pushing commands that take a while to receive the output, my expect receives the correct string to exit before all the output is displayed. I am thinking I need a "for" condition on my send "$cmds" but not sure how.

Here is my expect portion:
Code:
expect << EOF
set timeout 60
log_user 0
spawn telnet ${router}
expect "login: "
send "testusername\r"
expect "Password: "
send "testpass\r"
expect "*#"
send "term len 0\r"
expect "*#"
log_user 1
send "$cmds"  
expect "*$router#"
send "exit\r"
EOF
 
I got it working pretty good now. I put a unique string at the end of my cmds variable and changed the timeout to 240 right before when the commands are sent.
Code:
expect << EOF
set timeout 60
set var "exit    "
log_user 0
spawn telnet ${router}
expect "login: "
send "testusername\r"
expect "Password: "
send "testpass\r"
expect "*#"
send "term len 0\r"
expect "*#"
set timeout 240
log_user 1
send "$cmds"  
expect $var
send "exit\r"
EOF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top