Update:

Thanks for the suggestions, they got the old grey matter moving. I tried a few attempts with both suggestions (Expect & CLI). Neither proved fruitful immediately. However, as it so happens all to often for me, something in the examples of the other modules gave me a potential modification to the original approach.

I'm putting the code and output below for the benefit of others in case they are attempting something simular with the XR-IOS boxes from Cisco.

What I ended up doing was removing the loop for each command after the ssh connection was established. I instead added a check of the interface description followed by the original command. This was looped to create a single variable containing all the interfaces to be passed after the connection was made. It'may not be the prettiest but it is effective. I just now have to apply it to the larger script I am attempting to update.

Again, tahnks for the suggestions and making me look at this from a different perspective.
#!/usr/bin/perl -w use Net::Ping; use Net::OpenSSH; $username = "user"; $password = "password"; @interface = (); #Input data to fill above variables get_router_data(); $listfiles = system("ls -al /root/scripts/logs/interfaces/"); $deletefiles = system("rm -rf /root/scripts/logs/interfaces/*"); print "$listfiles\n$deletefiles\n\n"; print "\nAttempting to connect to routers...\n"; $pingtest = Net::Ping->new("icmp"); cisco_test(); print "\n\nThe End....\n\n"; sub get_router_data { $hostname = "router1"; $interface[0] = "Bundle-Ether11"; $interface[1] = "Bundle-Ether12"; $cmd = ""; foreach $intname (@interface) { $cmd = "$cmd\nshow interfaces $intname | include Bundle\nshow +interfaces $intname | include BW\n"; } } sub cisco_test { if ($pingtest->ping($hostname, 2)) { $ssh = Net::OpenSSH->new("$hostname", user => $username, passw +ord => $password, master_stderr_discard => 1) || warn("\$!\n"); $testcount = 0; print "\n\nPolling $hostname ......... please wait\n"; open (LOGONE, ">/root/scripts/logs/interfaces/log.$hostname.tx +t"); $out = $ssh -> capture ("$cmd"); print "$out\n"; print LOGONE $out; close (LOGONE); open (LOGTWO, "/root/scripts/logs/interfaces/log.$hostname.txt +"); $interfacecount = 0; @interfacenamerecord = (); @interfacespeedrecord = (); while ( <LOGTWO> ) { @splitset = split (/\s+/, $_); $speedcount = 0; foreach $splittest (@splitset) { if ($splittest =~ /Bundle/) { $interfacenamerecord[$interfacecount] = $splitset[ +0]; } if ($splittest =~ /BW/) { $locationcount = $speedcount+1; $interfacespeedrecord[$interfacecount] = $splitset +[$locationcount]; $interfacecount++; } $speedcount++; } } $printcount = 0; $intholder = ""; foreach $intholder (@interfacenamerecord) { print "Interface $interfacenamerecord[$printcount] reporte +d speed is $interfacespeedrecord[$printcount]\n"; $printcount++; } close (LOGTWO); $testcount++; } }
Evaluation output
[scripts]# perl cisco_crs_int_check.pl total 24 drwxr-xr-x. 2 root root 16384 Jan 30 14:20 . drwxr-xr-x. 4 root root 4096 Jan 29 10:12 .. -rw-r--r--. 1 root root 326 Jan 30 14:20 log.router1.txt 0 0 Attempting to connect to routers... Polling router1 ......... please wait Thu Jan 30 19:26:37.629 UTC Bundle-Ether11 is up, line protocol is up Thu Jan 30 19:26:37.975 UTC MTU 9192 bytes, BW 240000000 Kbit (Max: 240000000 Kbit) Thu Jan 30 19:26:38.268 UTC Bundle-Ether12 is up, line protocol is up Thu Jan 30 19:26:38.545 UTC MTU 9192 bytes, BW 340000000 Kbit (Max: 340000000 Kbit) Interface Bundle-Ether11 reported speed is 240000000 Interface Bundle-Ether12 reported speed is 340000000 The End....

In reply to Re: Net::OpenSHH unable to execute multiple commands with Cisco CRS? by Dranzaz
in thread Net::OpenSHH unable to execute multiple commands with Cisco CRS? by Dranzaz

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.