LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Expect Script Limitation (http://www.linuxquestions.org/questions/programming-9/expect-script-limitation-4175452652/)

lastkey 03-04-2013 09:55 AM

Expect Script Limitation
 
Hi Guys,

I wrote the below script which logs in certain cards and gets ps output. It works fine except for some cards, telnet fails for certain reason. For example, it worked fine for .13 but telnet to .15 failed, script will terminate here. I want it to continue logging in the rest of cards. The problem is this these IPs are not static nor the number of cards so I can't standardize it. I have to make a new script each time for different servers so each time I have to edit this script many times by removing the entries of cards for which telnet fails.

#!/usr/bin/expect
spawn telnet 172.16.9.13 8100
expect "U-Qtil>"
sleep 1
send "ps\n"
expect eof

spawn telnet 172.16.9.15 8100
expect "U-Qtil>"
sleep 1
send "ps\n"
expect eof

spawn telnet 172.16.9.17 8100
expect "U-Qtil>"
sleep 1
send "ps\n"
expect eof

lastkey 03-04-2013 11:05 AM

This problem is solved. I was getting below error when telnet failed, for expect to continue. I changed the code as below

spawn telnet 172.16.8.11 8100
Trying 172.16.8.11...
telnet: connect to address 172.16.8.11: Connection refused


#!/usr/bin/expect
spawn telnet 172.16.8.15 8100

expect {
"telnet:" {
sleep 1

}
"U-Qtil>" {
sleep 1
send "ps\n"
}
}
send "quit\r"
sleep 1
expect eof

spawn telnet 172.16.8.141 8100

expect {
"telnet:" {
sleep 1

}
"U-Qtil>" {
sleep 1
send "ps\n"
}
}
send "quit\r"
sleep 1
expect eof


All times are GMT -5. The time now is 06:00 AM.