2017-09-04 14 views
1

我寫了一個監控腳本來查看一些日誌進步,但是我堅持了下面的代碼,代碼繼續錯誤使用的Net :: OpenSSH的

$fh = $ssh->capture("find $servers{$agent}{$log} -mmin +10") or die "Unable to run command\n"; 
         chomp($fh); 

         if ($fh) { 
           print "Log are 10 minutes not moving. \n"; 
         } 
         else { 
           print "Log are running as usual. \n"; 
         } 

此代碼將拿出低於輸出,

無法運行命令

這表明有錯誤發生,但是我嘗試手動通過ssh運行命令完美的作品。

需要幫助來檢查此代碼。

+0

啥子呢'$ SSH-> error'說? – Botje

回答

0

如果find找不到任何內容,則capture返回爲空值的空字符串,因此將調用die

您可以檢查是否出現了錯誤調用error方法:

my $out = $ssh->capture("find $servers{$agent}{$log} -mmin +10"); 
$ssh->error and die "Unable to run command: " . $ssh->error;