Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, I try to use the module Net::OpenSSH with a Cisco to make simple test. I wish to execute 3 commands, without saving the result. The comman number 4 must capture the result. I use the system command for the 3 first and capture for the command 4. Unfortunatly, the command system seems to make problem.
use Net::OpenSSH; my $host = '192.168.109.10'; my $user = 'admin'; my $password = 'admin'; my $port = '22'; my $ssh = Net::OpenSSH->new( host =>$host, user => $user, port => $port, password => $password); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error +; my $fichier_dst = "$host\.txt"; open (FH_OUT, '>', '/home/alexandre/Python_script/CISCO/' . $fichier_d +st);; my $cmd1 = 'conf t'; my $cmd2 = 'hostname TOTO'; my $cmd3 = 'exit'; $ssh->system("$cmd1"); $ssh->system("$cmd2"); $ssh->system("$cmd3"); my $cmd4 = 'sh run \| i hostname'; my ($out, $err) = $ssh->capture2("$cmd4"); $ssh->error and die "remote find command failed: " . $ssh->error; print "$out\n"; print FH_OUT $out; close(FH_OUT);

Here the resultat.
Seems to make two connexions and blocked with password

If I use only the command capture, no problem of connexion.

**************************************************************************
* IOSv is strictly limited to use for evaluation, demonstration and IOS  *
* education. IOSv is provided as-is and is not supported by Cisco's      *
* Technical Advisory Center. Any use or disclosure, in whole or in part, *
* of the IOSv Software or Documentation to any third party for any       *
* purposes is expressly prohibited except as otherwise authorized by     *
* Cisco in writing.                                                      *
**************************************************************************
Enter configuration commands, one per line.  End with CNTL/Z.Connection to 192.168.109.10 closed by remote host.

**************************************************************************
* IOSv is strictly limited to use for evaluation, demonstration and IOS  *
* education. IOSv is provided as-is and is not supported by Cisco's      *
* Technical Advisory Center. Any use or disclosure, in whole or in part, *
* of the IOSv Software or Documentation to any third party for any       *
* purposes is expressly prohibited except as otherwise authorized by     *
* Cisco in writing.                                                      *
**************************************************************************Password: 

Thanks for your help.


In reply to Net::OpenSSH pass command by touriste75

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 pondering the Monastery: (8)
As of 2024-04-18 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found