#!/usr/bin/perl use strict; use warnings; use Time::HiRes qw/ usleep gettimeofday tv_interval/; use File::Basename; use Net::OpenSSH; use Expect; ################################# ## Configurables here ################################# our $test_host="myhost"; our $ssh_user="myuser"; our $HOME="/home/myuser"; our $dir="${HOME}/mytests"; our $ARG1=777; ################################# ## Variables here ################################# our %test_results ; our $Y = "OK"; our $N = "FAIL"; our @output_to_print ; my ($file, $fname,$text_to_print); our $now=`date +%m%d%Y_%H%M%S`; chomp($now); my ($stderr_fh, $stdout_fh); my $stdoutfile = "/tmp/$ARG1$now.log"; my $stderrfile = "/tmp/$ARG1$now.err"; our $LOG="/tmp/${ARG1}_${now}.log"; ################################# ## Main ################################# open $stdout_fh, '>>', "$stdoutfile" or die "cannot open stderr file"; open $stderr_fh, '>>', "$stderrfile" or die "cannot open stdout file"; # open a connection to the test server my $ssh = Net::OpenSSH->new("$ssh_user\@$test_host",default_stderr_fh => $stderr_fh, default_stdout_fh => $stdout_fh ); $ssh->error and die "SSH connection failed: " . $ssh->error; # Get the files to run my @files = $ssh->capture("ls $dir "); $ssh->error and die "remote ls command failed: " . $ssh->error; foreach $file(@files){ my $full_file="${dir}/$file"; my $fname = $file; $fname =~ s{\.[^.]+$}{}; print "$fname \n"; $text_to_print="test: $full_file Log: $LOG \n"; print $stdout_fh "$text_to_print \n"; my @output = $ssh->capture("$full_file "); if($ssh->error) { $test_results{"$fname"} = "$N"; } if(grep(/\b$Y\b/,@output)) { $test_results{"$fname"} = "$Y"; } else { if (grep(/\b$N\b/,@output)) { $test_results{"$fname"} = "$N"; } } print $stdout_fh "@output \n"; } print $stdout_fh "\nTest results\n#################\n"; while ((my $test, my $result) = each(%test_results)) { print $stdout_fh "$test, $result\n"; }