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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |