You don't need to read the content into a scalar then split it. Instead, directly assign to an array, like the documentation of Net::OpenSSH shows:
my @df_arr = $ssh->capture("df -k /home/ | tail -1") or die "Unable to + run command\n"; print "$s: Disk space /home/ = $df_arr[3] \n";
I find it very confusing if you name a variable $fh when it is not a filehandle.
If you want to make your code more concise, consider the introduction of different routines which return information given a server connection:
sub disk_space { my( $ssh, $dir ) = @_; my @df_arr = $ssh->capture("df -k '$dir' | tail -1") or die "Unabl +e to run command\n"; print "Disk space $dir = $df_arr[3]\n"; } disk_space( $ssh, '/home/' );
In reply to Re: Remotely collect server data using Net::OpenSSH Perl
by Corion
in thread Remotely collect server data using Net::OpenSSH Perl
by IruP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |