how to report error when remote commands fail

here is the sample of my script iam trying to run on remote systems and execute commands

#!/usr/bin/perl -w use strict; use Net::SSH::Perl; my $hostname = "192.168.1.17"; my $username = "root"; my $password = "Pass1234"; my $cmd = 'ls'; my $cmd1 = 'ling -c 2 -q 8.8.8.8'; my $cmd2 = 'ping -w 3 8.8.8.8'; my @cmds = ($cmd , $cmd1, $cmd2); my $ssh = Net::SSH::Perl->new("$hostname", debug=>0); $ssh->login("$username","$password"); foreach my $one(@cmds) { my ($stdout,$stderr,$exit) = $ssh->cmd("$one") ; print $stdout; }

the stdout is outputting "bash: ling: command not found " for the $cmd1 but if the commands fail and then the script should warn me

here below is the output

suse@linux-p9uj:~/junk/vm> ./vmain.pl anaconda-ks.cfg bash: ling: command not found PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=125 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=57 time=52.1 ms 64 bytes from 8.8.8.8: icmp_seq=3 ttl=57 time=211 ms --- 8.8.8.8 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 52.113/129.706/211.260/65.033 ms

what iam trying to finally achieve is to run the script and see all the logs and errors in one place


In reply to how to report error when remote commands fail by janasec

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.