My code involves going to a host(doing with openSSH), getting the list of files matching a pattern(doing using remote find command-OpenSSH) and then opening each file I have got and processing each(grepping etc). I am done with getting the file names and passing to a function. Now, I have to pass these filename to a function where I open each and process it. I am trying to do it using File::Remote as follows:
sub processFiles{
my $fileList =shift;
#Iterate over the file and try to find start and stop time stamps from the file
for my $file ( @{$fileList}) {
#finding start time of file:its found in lines of file
my $HEAD;
open $HEAD, "host:head -1000 $File|" or die "Unable to check file for starting time";
while ( <$HEAD> ) {
#process...
But I am unable to open the file on the host an I am getting an error.
When performing remote actions in batch, the first principle is to reduce the number of ssh connections (ideally only one). Using shell or perl one liner, you can do very complex actions. Here is my understanding of your need:
You can pipe further processing in the same line. If you want to process the files locally, you can transfer all the files in a single command. Here is a full example: