結果我需要找到,如果資源沒有聯機根據以下規則的bash +驗證從輸出
在資源名稱的情況下是在兩臺機器上MACHINE1和機2然後其中一人應該是上網,否則就需要打印資源是下降
在資源名稱的情況下,只在一個機器MACHINE1或機2則狀態應該就行,否則就需要打印資源下跌
任何想法如何使用bash或AWK實現呢?或perl一班?
Resource name machine name status
more file.txt
nis-master machine1 Stop
OnGuard-a machine1 Online
nis-slave machine2 Offline
OnGuard-b machine2 Offline
oracle-vip machine1 Online
oracle-vip machine2 Offline
oracle-disks machine1 Online
oracle-disks machine2 Offline
oracle-res machine1 Stop
oracle-res machine2 Offline
oracle-cluster machine1 Online
oracle-cluster machine2 Offline
例子 - 資源是在兩臺機器上(無需打印的資源向下)
Resource: oracle-vip machine1 Online
Resource: oracle-vip machine2 Offline
例子 - 資源是一臺機器上(需要打印的資源向下)
Resource: nis-master machine1 Stop
示例 - 資源位於兩臺機器上(需要打印資源已關閉)
Resource: oracle-vip machine1 Offline
Resource: oracle-vip machine2 Offline
同時我寫了下面的代碼(在bash),但也許有人可以提高它更好地短期解決方案
FIRST_LINE=` awk '{print $1}' file.txt | grep -v Resource `
for i in $FIRST_LINE
> do
> [[ ` grep -c $i file.txt ` -eq 1 ]] && [[ ` grep $i file.txt | awk '{print $3}' | grep -c Online ` -eq 0 ]] && echo $i no online
> [[ ` grep -c $i file.txt ` -eq 2 ]] && [[ ` grep $i file.txt | awk '{print $3}' | grep -c Online ` -eq 0 ]] && echo $i no online
> done
nis-master no online
nis-slave no online
OnGuard-b no online
oracle-res no online
oracle-res no online
你問[AWK中的許多問題(http://stackoverflow.com/search?q=user%3A2557854+is%3Aquestion+ [AWK]) 。我希望你至少能寫出一些僞代碼。你試過什麼了?另外,不要交叉帖子:http://unix.stackexchange.com/questions/158580/bash-verify-results-from-output – fedorqui 2014-10-01 10:54:46
嗨fedorqui - 我有這個問題的答案,請解決這個問題,所以我會回答 – maihabunash 2014-10-01 12:17:59
你可以編輯你原來的帖子,改進方法並指出你有什麼。最終,它會重新開放。檢查:[如果我不同意問題的結束?如何重新打開它?](http://stackoverflow.com/help/reopen-questions) – fedorqui 2014-10-01 12:41:03