Re: Off Topic Executing Commands with perl script

From: Tim Fletcher (groupstudy@fletchmail.net)
Date: Sat Mar 06 2004 - 13:42:04 GMT-3


$t->print("\n");

Will send a new line. One of the issues you can run into when connecting to a console, is you never know what mode you will be in. Unlike telnet, a console will stay in config mode even if you disconnect. The way I usually deal with this is to send 2 ^C first, then send new lines until you get a response.

# set ors and errmode, save current values
$ors = $t->output_record_separator('');
$errmode = $t->errmode('return');

# send 2 ^C
$t->print("\03\03");

# keep poking it until we get a response
foreach (1 .. 20) {
  last if $t->cmd(String => "\n",
                  Timeout => 1);
  # give up and bail
  die "could not get CLI prompt" if $_ == 20;
}

# reset ors and errmode
$t->errmode($errmode);
$t->output_record_separator($ors);

At 01:00 PM 3/5/04, Adam Asay wrote:
>I have added the prompt you recommended Bob, and also added the input_log you
>recommended Tim. What I get in the log is:
>
>User Access Verification
>
>Username: user
>Password:
>
>Then it times out. Normally when you telnet into a router you get a prompt
>back, but when you telnet to an async line on a terminal server it does not
>return anything. You have hit enter before you get a prompt. Does anyone
>know how I can get around this.
>
>I appreciate all the help.
>
>-Adam
>
>On Thursday 04 March 2004 4:34 pm, Tim Fletcher wrote:
>> Set the Input_log parameter to a filename. Run the script, the take a look
>> at the file it created. This should tell were it's failing.
>>
>> -Tim Fletcher
>>
>> At 07:10 PM 3/4/04, Adam Asay wrote:
>> >Sorry for the off topic, but I haven't been able to find anything on this.
>> >
>> >I am using the perl module net::telnet:cisco to try and script some
>> > managment tasks. Everything works great until I try and login to a
>> > router threw a terminal server.
>> >
>> >I get a "pattern match timed-out" error.
>> >
>> >Has anybody seen this, or can someone at lease point me in the right
>> > direction on how to resolve it.
>> >
>> >Thanks
>> >Adam
>> >
>> >_______________________________________________________________________
>> >Please help support GroupStudy by purchasing your study materials from:
>> >http://shop.groupstudy.com
>> >
>> >Subscription information may be found at:
>> >http://www.groupstudy.com/list/CCIELab.html
>>
>> _______________________________________________________________________
>> Please help support GroupStudy by purchasing your study materials from:
>> http://shop.groupstudy.com
>>
>> Subscription information may be found at:
>> http://www.groupstudy.com/list/CCIELab.html



This archive was generated by hypermail 2.1.4 : Thu Apr 01 2004 - 08:15:16 GMT-3