Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994100]
help
Chatterbox?
[Corion]: thezip: If you want to open vim and can live with opening a second console window, use start "The results" vim.exe c:\path\to\logfile .log
[thezip]: Ooops... I lied. I guess Cygwin is back. I'll just do a tail -f instead. Better. Sorry for the noise.
[Corion]: Once more, I'm looking for a sane client-side framework, but I guess these don't exist. Everything I look at either uses a weirdo home-grown templating language (like Angular in all its incarnations) or uses weirdo Javascript incarnations (like ...
[Corion]: ... Inferno.js, which uses ES2015) or uses some horrible amount of Javascript infrastructure before you can even render a single file.
[Corion]: I'd really like to create a dynamic frontend for my Google Keep clone, but so far, all the templating solutions seem to bring their own template language or require me to hand-code everything in (their own flavour of) Javascript. I'd like something ...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2017-03-27 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (321 votes). Check out past polls.