2017-02-17 44 views

回答

1

You can store the output of a command using command substitution

但是,你說你想檢查結果。如果存儲該字符串輸出,則需要解析它以僅查找「OK」(因爲ping時間可能不同),並處理橫幅信息等(儘管這相對容易)。

這將是簡單的看看返回代碼從tnsping命令,而不是它的輸出:

tnsping myDB 
echo $? 

可以測試的$?值。如果ping是好的,那麼它將是零;否則就是1.

你還沒有說你想對測試結果做什麼。如果你想顯示錯誤(如果有的話),如果它沒有任何結果,你可以將兩者結合起來:

RESULT=$(tnsping myDB) 
if [[ $? -ne 0 ]]; then 
    printf "Ping failed, output was\n\n" 
    printf "%s\n" "${RESULT}" 
fi 
相關問題