sub ops_do_ssh_shell { my ($cmd) = @_; #etc ... } #### sub ops_do_ssh_shell { my ($cmd) = @_; my $ssh; my $key_path = defined $cmd->{key} ? $cmd->{key} : $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}); $cmd->{cmd_ret_code} = 0 + $ssh->error; if ( $ssh->error ) { $cmd->{status} = 'failure'; $cmd->{cmd_ret_msg} = '' . $ssh->error; } chomp $cmd->{output}; chomp $cmd->{std_err}; } return $cmd; } #### my $cmd_status = ops_do_ssh_shell($cmd); #### my @commands = ( { name => 'command_name1', user => 'user1', host => 'server1.foo.com', command => 'rsync_command yadda yadda' }, { name => 'command_name2', user => 'user2', host => 'server2.foo.com', command => 'rsync_command yadda yadda' } ); for my $cmd (@commands) { if ($state->{status} eq 'success') { my $cmd_status = ops_do_ssh_shell($cmd); if ( (!defined $cmd_status->{cmd_ret_code}) or ($cmd_status->{cmd_ret_code} != 0) ) { $state->{status} = 'failure'; $state->{stack_trace} = $cmd_status; } } }