Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Vins,

Honestly I've always used "Net::SSH::Perl" module.

Found the interaction with TTY/PTYs to be less
troublesome. Not to mention retrieving large
amounts of "sh arp" and "sh cam dyn" from IOS/CATOS 
devices.

Here's a sample I use from my script for logging in.

###############


  $ssh = Net::SSH::Expect->new(
          host => $ip, 
          user => $suser,
          password => $spass,
          timeout => 3,
          log_file => "$ofdir/$stime.$bname.$ip.dump_out.$^T.txt",
          raw_pty => 1);

  $ok = $ssh->run_ssh();
  if(!(defined $ok) || ($ok eq "")) { $ok = 0; } else { $ok = 1; }

  if($debug == 1) { print "$meth... "; }
  $ok = $ssh->waitfor('key verification failed', 5);
  if((!$ok) || ($ok eq "")) { $ok = 0; }
  if($ok == 1) { if($debug == 1 ) { print "FOUND ERROR ID KEY FAILED\n"; } $fpssh = 1; }
   else { if($debug == 1) { print "DID NOT FIND.. CONTINUE\n"; } $fpssh = 0; } $ok = 0;

  if($fpssh == 1)
    {
    if($debug == 1) { print "FOUND host key failed PROMPT\n"; }

    $val = "host_key_failed_prompt";

    $ssh->close();
    exit;
    } #EO if($fpssh == 1)



    $meth = "FIND #";
    if($debug == 1) { print "$meth... "; }
    $ok = $ssh->waitfor('#', 30, -re);
    if((!$ok) || ($ok eq "")) { $ok = 0; }
    if($ok == 1) { if($debug == 1) { print "GO\n"; } $fppt = 1; }
     else { if($debug == 1) { print "ERROR\n"; } $fppt = 0; } $ok = 0;

    if($fppt != 1)
      {
      $val = "did_not_find_en_prompt";


      $ssh->close();
      exit;
      } #EO if($fpps == 1)

    $meth = "SEND SH ARP";
    if($debug == 1) { print "$meth... \n"; }
    $ssh->send($cmd);
    if($debug == 1) { print "GO\n"; }
    while(defined ($line = $ssh->read_line()))
      {
      if(!(defined $line) || ($line eq "")) { next; }
      if($debug == 1) { print "LINE: \"" . __LINE__ . "\" LINE: \"$line\"\n"; }
      push @outs, $line;
      }

    $ssh->send("\n\n");
##############

To show the current buffer from the script incase
of problems using "expect" like interactions..


    if($debug == 1) { print "PEEK: \"" . $ssh->peek(0) . "\" L: \"" . __LINE__ . "\"\n"; }

-- Notice the line "while(defined ($line = $ssh->read_line()))". 
This is different from the original line in the
documentation of "@outs = $ssh->waitfor('#', -re, 30);"
the "read line" is more fault tolerant.


-- I make sure each module (login, run command, exit)
is their own section of code, having nested if statements
is bad if your are using "parallel fork manager" and if 
you have to exit/next in the middle of the script.



Joe










In reply to Re: Net::SSH2 command output polling by t_rex_joe
in thread Net::SSH2 command output polling by VinsWorldcom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found