Use of uninitialized value $selector in split at /usr/local/share/perl/5.18.2/Net/OpenSSH/Parallel.pm line 141.
####
my @parts = split /\s*,\s*/, $selector;
####
#!/usr/bin/perl
use FiLeS;
use strict;
use warnings;
use Data::Dumper;
use processLogFiles;
use Fcntl qw(:flock);
use feature qw(state);
use Net::OpenSSH::Parallel;
my %WARNS = ();
my %dir_all = ();
my %sudo_passwords = ();
my $confFile = "conf.ini";
my $dirFile = "directories.ini";
my $objectFiles = FiLeS->new( "confRef" , "dirRef" );
my $refHashDir = $objectFiles->getFiles( $dirFile );
my $refHashconf = $objectFiles->getFiles( $confFile );
my $refHashDirectories = $objectFiles->makeDirectories( $refHashDir );
my $objectProcessLogFiles = processLogFiles->new( "refLogFile" , "refArrayConversion" , "refPrintOutput" );
# Find the version Ubuntu or Crux
my @data_files = getOsDistribution( $refHashconf , $refHashDir );
my $refhashProcessTimestampFile = $objectProcessLogFiles->processData( @data_files );
sub getOsDistribution {
my ( $hashRefconf , $hashRefDir ) = @_;
my @mps = sort keys ( $hashRefconf );
my $maximum_workers = @mps;
my $maximum_connections = 2 * $maximum_workers;
my $maximum_reconnections = 3;
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 = ();
my @log_files = ();
foreach my $hash ( @mps ) {
push (@log_files , "".$hashRefDir->{Directories}{log_dir}."/".$hashRefconf->{$hash}{log}."");
open $stdout_fh[$num] , '>' , "".$hashRefDir->{Directories}{log_dir}."/".$hashRefconf->{$hash}{log}.""
or warn "unable to create file: $hashRefconf->{$hash}{log} - $!";
open $stderr_fh[$num], '>>', "".$hashRefDir->{Directories}{err_dir}."/".$hashRefconf->{$hash}{error}.""
or warn "unable to create file: $hashRefconf->{$hash}{error} - $!";
$pssh->add_host( $hashRefconf->{$hash}{host} ,
user => $hashRefconf->{$hash}{user},
port => $hashRefconf->{$hash}{port},
password => $hashRefconf->{$hash}{psw},
default_stderr_fh => $stderr_fh[$num],
default_stdout_fh => $stdout_fh[$num] );
$sudo_passwords{$hashRefconf->{$hash}{host}} = $hashRefconf->{$hash}{psw};
$num++;
}
# hostname -I another way to get IP
$pssh->push('*', command => 'cat /etc/issue; echo %HOST%' );
$pssh->run;
closeFH( @stdout_fh , @stderr_fh );
my $refhashProcessData = $objectProcessLogFiles->processData( @log_files );
my %version_hash = ();
# Bind the IP's with the OS version
foreach my $key ( keys $refhashProcessData ) {
#print "$key: @{ $dev_info{$key} }\n";
$refhashProcessData->{$key}[0] = (split(/ /,$refhashProcessData->{$key}[0]))[0];
# Push the version into a hash pointing to the ip
push( @{$version_hash{$refhashProcessData->{$key}[0]} } , $refhashProcessData->{$key}[1] );
}
my $Crux_IPs = $version_hash{'CRUX'};
my $Ubuntu_IPs = $version_hash{'Ubuntu'};
my $refHashConvertArrayUbuntu = $objectProcessLogFiles->arrayConversion( $Ubuntu_IPs );
my $refHashConvertArrayCrux = $objectProcessLogFiles->arrayConversion( $Crux_IPs );
$pssh = Net::OpenSSH::Parallel->new(%opts);
$num = 0;
@stdout_fh = ();
@stderr_fh = ();
@log_files = ();
foreach my $hash ( @mps ) {
push (@log_files , "".$hashRefDir->{Directories}{log_dir}."/".$hashRefconf->{$hash}{log}."");
open $stdout_fh[$num] , '>' , "".$hashRefDir->{Directories}{log_dir}."/".$hashRefconf->{$hash}{log}.""
or warn "unable to create file: $hashRefconf->{$hash}{log} - $!";
open $stderr_fh[$num], '>>', "".$hashRefDir->{Directories}{err_dir}."/".$hashRefconf->{$hash}{error}.""
or warn "unable to create file: $hashRefconf->{$hash}{error} - $!";
$pssh->add_host( $hashRefconf->{$hash}{host} ,
user => $hashRefconf->{$hash}{user},
port => $hashRefconf->{$hash}{port},
password => $hashRefconf->{$hash}{psw},
default_stderr_fh => $stderr_fh[$num],
default_stdout_fh => $stdout_fh[$num] );
$sudo_passwords{$hashRefconf->{$hash}{host}} = $hashRefconf->{$hash}{psw};
$num++;
}
if ( grep { defined($_) } $refHashConvertArrayUbuntu ) {
my @Ubuntu_cmds = ( 'echo %HOST%' ,
"service ntp stop" ,
"ntpd -gq" ,
"service ntp start" );
sub ubuntu {
my ($label , $ssh , @cmd) = @_;
foreach my $c (@cmd) {
$ssh->system( {stdin_data => "$sudo_passwords{$label}\n"} ,
'sudo' , '-Skp' , '' , '--' , split " " , $c );
}
}
foreach my $Ubuntu_ip ( @{$refHashConvertArrayUbuntu} ) {
$pssh->push($Ubuntu_ip , parsub => \&ubuntu , @Ubuntu_cmds);
}
} # End of if grep $refHashConvertArrayUbuntu
if ( grep { defined($_) } $refHashConvertArrayCrux ) {
foreach my $Crux_ip ( @{$refHashConvertArrayCrux} ) {
$pssh->push($Crux_ip , command => 'echo %HOST%; /etc/rc.d/ntpd stop; ntpd -gq; /etc/rc.d/ntpd start;' );
}
}
$pssh->run;
closeFH( @stdout_fh , @stderr_fh );
#/usr/local/dag/tools/dagclock -d dag0 none overin
return @log_files;
}
sub closeFH {
foreach my $file (@_) {
close $file
or warn $! ? "Error closing ".$file.": $!"
: "Exit status $? from ".$file."\n";
}
}
local $SIG{__WARN__} = sub {
my $message = shift;
return if $WARNS{$message}++;
logger('warning', $message);
};
sub logger {
my ( $level , $msg ) = @_;
my $error = "$refHashDirectories->{Directories}{warn_dir}/error.err";
open my $out, '>>', "".$error.""
or die "Could not open file: ".$error." - $!\n";
flock( $out , LOCK_SH )
or die "Could not lock '".$out."' - $!\n";
chomp $msg;
my $datestring = localtime();
print $out "".$level." - ".$msg." - ".$datestring."\n";
close $out
or die "Could not close file: ".$error." - $!\n";
}
####
#!/usr/bin/perl
use strict;
use warnings;
package processLogFiles;
sub new {
my $class = shift;
my $devices = {
refArrayProcess => shift,
refArrayConversion => shift,
refArrayPrintOutputFile => shift,
};
bless $devices, $class;
return $devices;
}
sub processData {
use Fcntl qw( :flock );
my ( $devices , @stdin ) = @_;
my %file_hash = ();
foreach my $file (@stdin) {
open my $file_handle , '<' , $file
or warn "unable to open file: ".$file." $!";
flock( $file_handle , LOCK_SH )
or die "Could not lock '".$file."' - $!\n";
my $log_file = (split(/\//,$file))[-1];
# Remove \n character and also blank lines
chomp(my @lines = grep /\S/, <$file_handle>);
# Push the data into a hash
push(@{$file_hash{$log_file}}, @lines);
close $file_handle
or warn "unable to close file: ".$file." $!";
}
return $devices->{refArrayProcess} = \%file_hash if (%file_hash);
}
sub arrayConversion {
use Fcntl qw( :flock );
my ( $devices , @twoDimensionArray ) = @_;
my @result;
while ( @twoDimensionArray ) {
my $next = shift @twoDimensionArray;
if ( ref($next) eq 'ARRAY' ) {
unshift @twoDimensionArray , @$next;
}
else {
push @result, $next;
}
}
return $devices->{refArrayConversion} = \@result if (@result);
}
sub processTimestampFile {
use Data::Dumper;
my ( $devices , @log_file ) = @_;
print Dumper \@log_file;
exit 0;
my %info = %{ shift() };
my $data = "data.txt";
open my $write , '>>' , $data
or die "Could not open file: ".$data." - $!\n";
flock( $write , LOCK_SH )
or die "Could not lock '".$data."' - $!\n";
my %data_hash = ();
foreach my $data_file ( sort { @{$info{$b}} <=> @{$info{$a}} } keys %info ) {
#print "$data_file: ", join(", ", sort @{ $info{$data_file} }), "\n";
$data_hash{$info{$data_file}[0]} = $info{$data_file}[3];
printf $write "%s %s\n" , $info{$data_file}[0] , $info{$data_file}[3];
}
close $write
or die "Could not close '".$data."' - $!\n";
#return $devices->{refArrayPrintOutputFile} = \%data_hash if (%data_hash);
}
1;
####
#!/usr/bin/perl
use strict;
use warnings;
package FiLeS;
sub new {
my $class = shift;
my $files = {
dirRefFile => shift,
confRefFile => shift,
};
bless $files, $class;
return $files;
}
sub getFiles {
use Config::IniFiles;
use Fcntl qw( :flock );
my ( $files , $dataFiles ) = @_;
open my $fh , '<' , "".$dataFiles.""
or die "Could not open file: ".$dataFiles." - $!\n";
flock( $fh , LOCK_SH )
or die "Could not lock '".$dataFiles."' - $!\n";
tie my %ini, 'Config::IniFiles', ( -file => "".$dataFiles."" )
or die "Error: IniFiles->new: @Config::IniFiles::errors";
close $fh
or die "Could not close '".$dataFiles."' - $!\n";
return $files->{dirRefFile} = \%ini if (%ini);
}
sub makeDirectories {
my ( $files , $hash_dir ) = @_;
foreach my $dir ( sort keys %{ $hash_dir } ) {
#print $dir . " {\n";
foreach my $keys ( keys %{ $hash_dir->{ $dir } } ) {
#print "\t" . $keys . " \t=> ";
foreach my $path ( $hash_dir->{ $dir }->{ $keys } ) {
#print $path . "\n";
unless(-e $path or mkdir $path) {
mkdir ($path , 0755);
}
}
}
#print "}\n";
}
return $files->{ dirRefFile } = $hash_dir if ( $hash_dir );
}
1;
####
[MP 100]
host = 0.0.0.0
user = username
psw = password
port = 22
log = MP_100.log
error = MP_100.err
[MP 101]
host = 0.0.0.0
user = username
psw = password
port = 22
log = MP_101.log
error = MP_101.err
####
[Directories]
log_dir = /home/LOG
err_dir = /home/ERROR
warn_dir = /home/WARN