Hello again vikas330

I found some time and I put together 80% - 90% of the work of your request.

Attention!!! in my example I am using ssh key exchange, in case you are not using that uncomment the psw on add user (password) and comment out the (key_path).

Here is the code to do that:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::OpenSSH::Parallel; #$Net::OpenSSH::Parallel::debug = -1; my %hosts = ( localhost => { host => "localhost", user => "user", port => "22", # default 22 psw => "psw", # use only if no ssh keys key => "/home/user/.ssh/id_rsa", # linux default di +r dir => "/home/user/LOG", log => "output1.txt", error => "error1.txt", }, localhost_2 => { host => "127.0.0.1", user => "user", port => "22", psw => "psw", key => "/home/user/.ssh/id_rsa", dir => "/home/user/LOG", log => "output2.txt", error => "error2.txt", }, ); my @commands = ( 'echo %HOST%' , 'df -h' ); # Remove first command if +unecessary # is the maximun number of remote commands that can be running concurr +ently. my $maximum_workers = @commands; # it is recomended that maximum_connections >= 2 * maximum_workers my $maximum_connections = 2 * $maximum_workers; my $maximum_reconnections = 0; my %opts = ( workers => $maximum_workers, connections => $maximum_connections, reconnections => $maximum_reconnections ); my $pssh = Net::OpenSSH::Parallel->new( %opts ); my $num = 0; my @stdout_fh = (); my @stderr_fh = (); foreach my $label (keys %hosts) { mkdir $hosts{$label}{dir} unless -d $hosts{$label}{dir}; # Open file and append open($stdout_fh[$num], '>', $hosts{$label}{dir}."/".$hosts{$label} +{log}) or die "Could not open file '$hosts{$label}{dir}/$hosts{$label}{lo +g}' $!"; # Open file and append write open($stderr_fh[$num], '>>', $hosts{$label}{dir}."/".$hosts{$label +}{error}) or die "Could not open file '$hosts{$label}{dir}/$hosts{$label}{er +ror}' $!"; $pssh->add_host( $hosts{$label}{host}, user => $hosts{$label}{user}, port => $hosts{$label}{port}, #password => $hosts{$label}{psw}, default_stdout_fh => $stdout_fh[$num], default_stderr_fh => $stderr_fh[$num], key_path => $hosts{$label}{key}, ); $num++; } # Assigning all commands to all hosts $pssh->push('*', command => $_ ) for @commands; $pssh->run; closeFH ( @stdout_fh , @stderr_fh ); print Dumper fileProcessing(); sub closeFH { foreach my $fh (@_) { close $fh or die "Error closing $!\n"; } } sub fileProcessing { my $ref_hash = {}; foreach my $label (keys %hosts ) { # Open file to read open(my $fh, '<', $hosts{$label}{dir}."/".$hosts{$label}{log}) or die "Could not open file '$hosts{$label}{dir}/$hosts{$label +}{log}' $!"; chomp( my @data = <$fh> ); close $fh or die "Could not close file '".$hosts{$label}{dir}."/".$hosts +{$label}{log}."' $!";; $$ref_hash{$label} = \@data; } return $ref_hash; } __END__ $VAR1 = { 'localhost' => [ 'localhost', 'Filesystem Size Used Av +ail Use% Mounted on', 'udev 7.8G 0 7 +.8G 0% /dev', 'tmpfs 1.6G 9.7M 1 +.6G 1% /run', '/dev/mapper/ubuntu--vg-root 218G 15G 1 +93G 8% /', 'tmpfs 7.8G 86M 7 +.8G 2% /dev/shm', 'tmpfs 5.0M 4.0K 5 +.0M 1% /run/lock', 'tmpfs 7.8G 0 7 +.8G 0% /sys/fs/cgroup', '/dev/sda2 473M 125M 3 +24M 28% /boot', '/dev/sda1 511M 3.6M 5 +08M 1% /boot/efi', 'cgmfs 100K 0 1 +00K 0% /run/cgmanager/fs', 'tmpfs 1.6G 68K 1 +.6G 1% /run/user/1000' ], 'localhost_2' => [ '127.0.0.1', 'Filesystem Size Used +Avail Use% Mounted on', 'udev 7.8G 0 + 7.8G 0% /dev', 'tmpfs 1.6G 9.7M + 1.6G 1% /run', '/dev/mapper/ubuntu--vg-root 218G 15G + 193G 8% /', 'tmpfs 7.8G 86M + 7.8G 2% /dev/shm', 'tmpfs 5.0M 4.0K + 5.0M 1% /run/lock', 'tmpfs 7.8G 0 + 7.8G 0% /sys/fs/cgroup', '/dev/sda2 473M 125M + 324M 28% /boot', '/dev/sda1 511M 3.6M + 508M 1% /boot/efi', 'cgmfs 100K 0 + 100K 0% /run/cgmanager/fs', 'tmpfs 1.6G 68K + 1.6G 1% /run/user/1000' ] };

If you open the file 'output1.txt' you will see something like:

localhost Filesystem Size Used Avail Use% Mounted on udev 7.8G 0 7.8G 0% /dev tmpfs 1.6G 9.7M 1.6G 1% /run /dev/mapper/ubuntu--vg-root 218G 15G 193G 7% / tmpfs 7.8G 89M 7.7G 2% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda2 473M 125M 324M 28% /boot /dev/sda1 511M 3.6M 508M 1% /boot/efi cgmfs 100K 0 100K 0% /run/cgmanager/fs tmpfs 1.6G 76K 1.6G 1% /run/user/1000

If you open the file 'output2.txt' you will see something like:

127.0.0.1 Filesystem Size Used Avail Use% Mounted on udev 7.8G 0 7.8G 0% /dev tmpfs 1.6G 9.7M 1.6G 1% /run /dev/mapper/ubuntu--vg-root 218G 15G 193G 7% / tmpfs 7.8G 89M 7.7G 2% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda2 473M 125M 324M 28% /boot /dev/sda1 511M 3.6M 508M 1% /boot/efi cgmfs 100K 0 100K 0% /run/cgmanager/fs tmpfs 1.6G 76K 1.6G 1% /run/user/1000

Next step is to create a function (sub) to open and process the files that you have created, I will leave this part for you.

Update: adding mkdir in foreach loop and dir in %hosts.

Update 2: adding open file and parse data into hash. I could resist of printing something as an output. Alternatively someone has to check the file(s).

Hope this helps...

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: multiple machines disk space alert by thanos1983
in thread multiple machines disk space alert by vikas330

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.