2014-02-21 144 views
0

我試圖執行下面的腳本,Case語句沒有顯示任何輸出

data=$(printf "%s " $(find output.log -type f -exec grep 'ACTIVE\| NOT ACTIVE' {} \; | awk '{print $1}')) 
    status=`find output.log -type f -exec grep 'ACTIVE\| NOT ACTIVE' {} \; | awk '{print $3}'` 

    case "$data" in 
    ("Instance1") 

      echo "Status for Instance1 is : $status"; 
     ;; 
    ("Instance2") 

      echo "Status for Instance2 is : $status"; 
     ;; 
    "") echo "empty things" 
    ;; 
    esac 

,但它沒有顯示任何輸出..也許我失去了一些東西在我的腳本(可能很多)

我在上面的腳本中使用的是logfile即ie。 output.log

INSTANCE_NAME OPEN_STATUS  STATUS 
---------------- ------------ ----------------- 
Instance1 OPEN   ACTIVE 

Instance2 OPEN   NOT ACTIVE 

誰能告訴我上面的腳本有什麼問題嗎?

感謝,

+0

感謝拉傑什編輯它適當的格式 – Mahesh

回答

1

你不循環在你的項目,所以你永遠不會有一個數據「的Instance1」但「的Instance1實例2」。 你可能想要的東西,如下所示:

items=$(grep -0 'ACTIVE\| NOT ACTIVE' output.log | tr -s ' ') 
IFS=$'\r\n' 
for it in $items; do 
    data=$(echo $it | cut -d ' ' -f1) 
    status=$(echo $it | cut -d ' ' -f3-) 
    case "$data" in 
    ("Instance1") 
    echo "Status for Instance1 is : $status"; 
     ;; 
    ("Instance2") 
     echo "Status for Instance2 is : $status"; 
     ;; 
    "") echo "empty things" 
    ;; 
    esac; 
done 
+0

它顯示所需的輸出。感謝您的所有努力。 – Mahesh