Hi All,
I'm an inexperienced perl coder and could really use some help here.
I'm trying to connect to a series of machines via ssh, call a script on each that returns formatted data and process the data in turn. This sub is used to retrieve the data from each machine and store it in a hash...
sub get_remote_file {
print "Retrieving data file...";
my @site_data;
chomp( @site_data = `$conx` );
if ( $? >> 8 ) {
print "Failed!\n";
} else{
print "Success!\n";
}
for $line( @site_data ) {
( $name, $filepath, $mod, $md5 ) = split( "\,", $line );
$site_data{$name} = ["$filepath", "$mod", "$md5"];
}
@site_data = ();
}
Which is called from within:
foreach $client ( @clients ) {
my ( %site_data, %office_data );
print "Performing Sentinel check on $client\n";
get_client_configs( $client );
print "Retrieving data from site...\n";
get_remote_file;
generate_local_data;
compare_files;
print "Completed Sentinel check on $client\n";
}
get_client_configs updates the $conx variable among other things. The $conx variable holds the connection string, eg 'ssh host ~/myscript'.
The problem I'm having is that the first time through the loop everything works fine and the hash is properly populated. However on every subsequent call the @site_data ends up with a single element containing all the data returned from the script on the remote machine. As you can see it screws up the populating of the hash.
Can anyone please help? Before you say it I cannot install any modules to help with this, it's not my machine.