Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Perl Expect is not sending multiple commands

by Argel (Prior)
on Sep 17, 2012 at 20:51 UTC ( #994100=note: print w/replies, xml ) Need Help??

in reply to Perl Expect is not sending multiple commands

Could you be Suffering from Buffering for the log file? Could you have the network device syslog the commands being executed instead of trying to rely on logging them in your script instead?

FWIW, here's what I used to do in 7+ year old script:

print $expect_instance "show system\r"; ( $which, $why, $match, $before, $after ) = $expect_instance->expect( +$Timeout, '#'); if( ! $which ) { mylog( $dev, 'sho_sys', $why ); return; } $sho_sys = $before;
Not familiar with the sub method you are using, but the last time I used Perl Expect was several years ago. :(

Elda Taluta; Sarks Sark; Ark Arks
My deviantART gallery

Replies are listed 'Best First'.
Re^2: Perl Expect is not sending multiple commands
by essej1 (Novice) on Sep 18, 2012 at 15:33 UTC

    Well chalk this up to not paying attention to the output. Expect was working as expected (bad pun intended). The issue turned out to be that the 'sh ver' command contains the device name. I was looking for the device name in the expect statement. Therefore, the expect was stopping mid output. I used your example of getting the various return items to get the last character in the prompt, which I concatenated to the device name for future prompts. I had to wait until the password was successful to get that bit of information (the $after). This matters as some devices use '#' and some use '>'.

    Paradise: Florida, full tank of gas, no appointments.
      Usually '#' indicates you are in enable mode and '>' indicates you are in normal mode (i.e. not all commands are available).

      I think you can do a regex like below (untested), though there is probably a cleaner/better way to do it.

      ($which,$why,$match,$before,$after) = $expect_instance->expect($Timeou +t, '-re', "(#)|(>)");

      Elda Taluta; Sarks Sark; Ark Arks
      My deviantART gallery

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994100]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-06-24 05:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.