From: Bradford R. <bt...@po...> - 2007-11-05 15:59:37
|
I spent a long time (longer than I should have) trying to come up with the perfect solution for this, but it's a tough one because there are lots of unexpected situations that can get in the way and leave your script hanging becuase it either missed something that didn't fit your regexp or misinterpreted some extra output as a prompt. In general, I found the easiest and most reliable solution was to try to have your script autodetect the prompt under the assumption that it would be the last line of text after you enter your password. If you can manage to autodetect it reliably, then you can use in subsequent expect() calls rather than a regular expression. You just have to make sure your script waits long enough after sending the password before it tries to detect the prompt... sometimes there's a hiccup during login and the prompt takes a half-second or so to be sent, and if there's any preceeding output such as a motd/banner the script might grab that instead. It's a good thing that these are all cisco devices, so the output should be more consistent and predictable than on unix boxes. Good luck. -- Brad On 11/2/07, amit1017 <gos...@ho...> wrote: > > > Hi guys, > > I am new to perl and expect. I started putting a script together that > telnets into desired devices one at a time and runs specified commands. > Problem I have is, that the prompt on this hosts does not follow a certain > norm. Some prompts are in caps, some are in lower caps. Normally, > prompts > are device names, but in some case our device names exceeds the number of > characters allowed in the hostname, so it cuts of the exceeded > letters. So > having the following doesn't really work at times: > > $telnet->expect($timeout, "$HostName"); > > Is there anyway, I can do this. That once I spawn the telnet session and > log in. The prompt that it gets, it stores it into a variable and than I > can leverage that variable throughout my script wherever it expects a > prompt. > > Also, these devices are all cisco devices. Is there a recommended timeout > values? I have $telnet->exp_internal(1) in my script. So In middle of the > output after a command is run, I see several /r's. Thanks in advance for > your help. > > Amit. > -- > View this message in context: > http://www.nabble.com/Having-problems-with-prompt-tf4737304.html#a13547267 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com > . > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |