| |||||||||||
expect_out Posted by naveenpn (naveenpn), 9 January 2008 Hi,I have basic problem with expect_out. I have been trying to fix this for quite sometime in different scripts and always failed. My understanding is send "<something>" expect "<something_else>" At this point the expect_out(buffer) should contain whatever is sent out from send until got the expected match. Here is the piece of code... expect # send "\r" expect # send "\r" expect # send "\r" expect # puts ">>>>> Sending $line\r" send "$line \r" expect # puts ----=> puts $expect_out(buffer) puts <=--- I am sending some of my commands to telnet session (configuring a system). Before the above piece of code, I do expect and send some more commands. This piece is special because I need to process the output of the command stored in "$line". Here is the output switch(config-if-hsrp)# ex switch(config-if)# ip add 6.6.6.6 255.0.0.0 switch(config-if)# hsrp 1 switch(config-if-hsrp)# ip 6.6.6.100 switch(config-if-hsrp)# ex switch(config-if)# ip add 4.4.4.4 255.0.0.0 switch(config-if)# ip add 4.4.4.60 255.0.0.0 sec switch(config-if)# hsrp 1 switch(config-if-hsrp)# no ip <<<--------- till here all the above command were sent out using expect # and send $command ------ >>> switch(config-if-hsrp)# switch(config-if-hsrp)# switch(config-if-hsrp)# switch(config-if-hsrp)# >>>>> Sending ip 4.4.4.4 ip 4.4.4.4 ERROR: Invalid IP address((VIP & Interface IP clash)) switch(config-if-hsrp)# ----=> switch(config-if-hsrp)# <=--- Between "----=> and <=----" is the expect_out(buffer). I was expecting "ERROR: Invalid IP address((VIP & Interface IP clash))" to be in expect_out(buffer) but I have only the prompt. Same script after some more commands switch(config-if-hsrp)# no ip switch(config-if-hsrp)# switch(config-if-hsrp)# switch(config-if-hsrp)# switch(config-if-hsrp)# >>>>> Sending ip 4.4.4.60 sec ip 4.4.4.60 sec switch(config-if-hsrp)# ----=> no ip switch(config-if-hsrp)# <=--- In this $expect_out(buffer) has no ip switch(config-if-hsrp)# but I was expecting empty. With some hack it worked once but not consistent. Looks like my basic understanding of expect_out buffer has gone wrong Can anyone help me ? Thanks Naveen Posted by admin (Graham Ellis), 9 January 2008 Are you, perhaps, getting out of step? In other words, sending your information one step ahead and using the buffering of the device to let you do so?Posted by naveenpn (naveenpn), 9 January 2008 <original message>Are you, perhaps, getting out of step? In other words, sending your information one step ahead and using the buffering of the device to let you do so? <original message> Thanks for quick response. Am I going out of step. I am not sure about that. I showed it few people. No one thought I am out-of-sync. Please point me if so. Ahead you mean expect # send "$line\r" expect # send "\r" expect # .... refer expect_out(buffer) here..... ? Can you explain more if my understanding is incorrect ? Thanks Naveen Posted by admin (Graham Ellis), 10 January 2008 [quote author=naveenpn]Am I going out of step. I am not sure about that. [/quote] Fair enough - I'm not there to see how it runs / what happens on timeouts and so forth, so I can only make suggestions of the common reasons for these sorts of problems. Of all the languages we work in, the expect issues like this are the most difficult to debug and trace via a forum as you have the interaction and timing between different processes to to consider. You'll probably do far better continuing to work with the expects you're actually shown it to locally that via a long distance lin such as this one where it's very hard to convery the timing issues. Posted by naveenpn (naveenpn), 10 January 2008 Hi Graham,Thanks for your suggestion. I tried showing to people here and no one has a clue....at least those whom I consulted now. I am having issue with expect_out(buffer) from past 3 years Everytime I have to do a hack to make it work. Yesterday I introduced some "empty" command before I sent the special command and after that I introduced some empty commands. Finally looks like it is working fine. Do not know when it will break though . You mentioned about some timing issue. Will we have timing issues if we are using multi-core multi-processor and is there a way we can tell the script not to run across threads/cores/processors or any other work around for timing issues ? Appreciate your interest and response. Naveen Posted by admin (Graham Ellis), 10 January 2008 I doubt very much whether it's a multiprocessor issue - more like a timing one. If the delays sort you, then you are probably NOT out of step, but I think you are sending before you have the complete prompt and that could be an issue.1. Try replacing expect # with expect "# " (note the space after the #!) 2. Have a look at the -s and -h options on send. They may help. Posted by naveenpn (naveenpn), 11 January 2008 Thanks. I will try this out.This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |