+ use Net::OpenSSH;
+ my $opt = { @_ };
+ open my $def_in, '<', '/dev/null' or die "unable to open /dev/null\n";
+ my $ssh = Net::OpenSSH->new(
+ $opt->{'user'}.'@'.$opt->{'host'},
+ 'default_stdin_fh' => $def_in
+ );
+ # ignore_all_errors doesn't override SSH connection/auth errors--
+ # probably correct
+ die "Couldn't establish SSH connection: ". $ssh->error if $ssh->error;
+
+ my $ssh_opt = {};
+ $ssh_opt->{'stdin_data'} = $opt->{'stdin_string'}
+ if exists($opt->{'stdin_string'}) and length($opt->{'stdin_string'});
+
+ my ($output, $errput) = $ssh->capture2($ssh_opt, $opt->{'command'});
+
+ return if $opt->{'ignore_all_errors'};
+ #die "Error running SSH command: ". $ssh->error if $ssh->error;
+
+ if ( ($output || $errput)
+ && $opt->{'ignored_errors'} && length($opt->{'ignored_errors'})
+ ) {
+ my @ignored_errors = split('\n',$opt->{'ignored_errors'});
+ foreach my $ignored_error ( @ignored_errors ) {
+ $output =~ s/$ignored_error//g;
+ $errput =~ s/$ignored_error//g;
+ }
+ $output =~ s/[\s\n]//g;
+ $errput =~ s/[\s\n]//g;
+ }
+
+ die (($errput || $ssh->error). "\n") if $errput || $ssh->error;
+ #die "$errput\n" if $errput;
+
+ die "$output\n" if $output and $opt->{'fail_on_output'};
+ '';