LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-04-2013, 10:55 AM   #1
lastkey
LQ Newbie
 
Registered: Nov 2006
Location: Accra, Ghana
Posts: 5

Rep: Reputation: 0
Question 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

Last edited by lastkey; 03-04-2013 at 10:56 AM.
 
Old 03-04-2013, 12:05 PM   #2
lastkey
LQ Newbie
 
Registered: Nov 2006
Location: Accra, Ghana
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
expect, linux, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
Is that limitation of shell script? sysmicuser Linux - Newbie 6 02-17-2013 07:14 PM
[SOLVED] script arg or parameters limitation jao_madn Programming 3 04-22-2012 10:39 AM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM


All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration