use Net::OpenSSH; my $host = "$ip"; my $user = 'root'; my $passphrase = 'uxxxxxD'; my $key = '/root/.ssh/id_rsa'; my $cmd="sh $script"; my %param = ( user => $user, passphrase => $passphrase, key_path => $key, timeout => 100 ); my $ssh = Net::OpenSSH->new($host,%param); my ($stdout,$stderr,$exit) = $ssh->capture2("$cmd"); my $exit = ($? >> 8); print "$exit is $exit "; sleep (10); if($exit == 0){ print "publish success "; print $stdout; open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" ); print F ("ErrorCode:$exit "); print F ("ErrorMsg:$stderr "); print F ("$stdout "); close F; $c->render(text => 'publish success') } else { print $ssh->error; $stderr and print $stderr; open( F, ">>", "/home/scan/mojo/log/$app-$ip-$XDATE.log" ); print F ("ErrorCode:$exit "); print F ("ErrorMsg:$stderr "); print F ("$stdout "); close F; $c->render(text => "ErrorCode:$exit;ErrorMsg:$stderr") }