Valid code as per request.

#!/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"; }

I've tried the following with no success

# DOESNT WORK?? the $ARG1 causes problems? my @output = $ssh->capture("$full_file $ARG1 $LOG"); # doesnt work my( $in, @output, $err, $pid ) = $ssh->open3("$full_file $ARG1 $LOG"); # DOESNT WORK?? my @output = $ssh->capture(stdin_data => "$full_file $ARG1 $LOG ");

In reply to Re: Net::OpenSSH capture and cmd w/args by eonarts
in thread Net::OpenSSH capture and cmd w/args by eonarts

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.