sub ops_do_ssh_shell { my ($cmd) = @_; my $ssh; my $key_path = $ENV{HOME} . '/.ssh/id_rsa'; if ( ops_cmd_status($cmd) ) { $ssh = Net::OpenSSH->new($cmd->{host}, user => $cmd->{user}, key_path => $key_path); if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{ssh_retcode}, $cmd->{ssh_retmsg}) = (0 + $ssh->error, '' . $ssh->error); } } if ( ops_cmd_status($cmd) ) { ($cmd->{output}, $cmd->{std_err}) = $ssh->capture2($cmd->{command}); if ( $ssh->error ) { $cmd->{status} = 'failure'; ($cmd->{child_retcode}, $cmd->{child_retmsg}) = (0 + $ssh->error, '' . $ssh->error); } chomp $cmd->{output}; chomp $cmd->{std_err}; } return $cmd; } sub ops_cmd_status { my ($cmd) = @_; defined $cmd->{status} or $cmd->{status} = 'success'; $cmd->{status} eq 'success' ? 1 : 0; } #### my $cmd = { user => 'oracle', host => 'randomdbserver.randomdomain.com', command => '/randompath/random_oracle_script' }; my $status = ops_do_ssh_shell($cmd);