else条件はbashスクリプトには表示されません

else条件はbashスクリプトには表示されません

誰でもこの問題を解決するのに役立ちますか?

このスクリプトは、複数のサーバーを監視し、ログにそのエラー状態を表示するためのものです。他のサーバーで使用するのと同じロジックですが、動作しており、同じようにエンコードされても動作しないものがあります。

ここで何が起こるのかは、警告状態を抽出したが警告がすべてのif条件を満たしていない場合、else条件の最後の部分である警告なし状態を表示しないことです。スペースで表示されます。助けてくれてありがとう。

for ((i=0;i<${#arrPNMIP[@]};++i)); do

ssh -o ConnectTimeout=30 ${arrPNMIP[i]} cat /logs/notificationmanager.log |
    grep -i ALARM | grep ${_date}T${_hour} |
    tail -1 > ${_dir}overload_${arrPNMHOST[i]}.txt
ssh -o ConnectTimeout=30 ${arrPNMIP[i]} cat /logs/notificationmanager.log |
    grep 'disconnectUnsafe disconnected host' | grep ${_date}T${_hour} |
    tail -1 > ${_dir}DCHU_${arrPNMHOST[i]}.txt


_count=$(wc -l ${_dir}overload_${arrPNMHOST[i]}.txt | awk '{print $1}')
_timestamp=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | awk '{print $1}' |
    tail -1 | cut -c 10-13)
_typeR=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep RAISED | wc -l)
_typeC=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep CEASED | wc -l)
_overload=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep -i overload | wc -l)
_sftp=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep -i sftp | wc -l)
_linkbus=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep -i linkbus | wc -l)
_dbconn=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep -i dbconn | wc -l)
_hbmgr=$(cat ${_dir}overload_${arrPNMHOST[i]}.txt | grep -i hbmgr | wc -l)

_DChostUnsafeCount=$(cat ${_dir}DCHU_${arrPNMHOST[i]}.txt |
    grep 'disconnectUnsafe disconnected host' | wc -l)
_dcIPhostUnsafe=$(cat ${_dir}DCHU_${arrPNMHOST[i]}.txt |
    grep 'disconnectUnsafe disconnected host' | awk -F " " '{print $8}' |
    cut -c 2-14 )


#echo ""

if (( ${_count[@]} >= 1)) || (( ${_DChostUnsafeCount[@]} >= 1));
then
  if (( ${_typeR[@]} >= 1)) && (( ${_overload[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}RAISED ALARM "\
"OVERLOAD at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeR[@]} >= 1)) && (( ${_sftp[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}RAISED ALARM "\
"SFTP at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeR[@]} >= 1)) && (( ${_linkbus[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}RAISED ALARM "\
"LINKBUS at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeR[@]} >= 1)) && (( ${_dbconn[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}RAISED ALARM "\
"DBCONN at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeR[@]} >= 1)) && (( ${_hbmgr[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}RAISED ALARM "\
"HBMGR at ${_timestamp}${BG_NC}"
  fi
  if (( ${_DChostUnsafeCount[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_RED}${F_BLACK}Disconnected "\
"Host with IP:${_dcIPhostUnsafe} at ${_timestamp}${BG_NC}"
  fi

  if (( ${_typeC[@]} >= 1)) && (( ${_overload[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_YELLOW}${F_BLACK}CEASED ALARM "\
"OVERLOAD at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeC[@]} >= 1)) && (( ${_sftp[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_YELLOW}${F_BLACK}CEASED ALARM "\
"SFTP at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeC[@]} >= 1)) && (( ${_linkbus[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_YELLOW}${F_BLACK}CEASED ALARM "\
"LINKBUS at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeC[@]} >= 1)) && (( ${_dbconn[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_YELLOW}${F_BLACK}CEASED ALARM "\
"DBCONN at ${_timestamp}${BG_NC}"
  fi
  if (( ${_typeC[@]} >= 1)) && (( ${_hbmgr[@]} >= 1 ));
  then
    echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_YELLOW}${F_BLACK}CEASED ALARM "\"
"HBMGR at ${_timestamp}${BG_NC}"
  fi

else
  echo -e "${arrPNMHOST[i]} ${arrPNM[i]}:${BG_GREEN}${F_BLACK}NO ALARM${BG_NC}"
fi
done

=================================================================
sample result display of the script

Event Detection Trigger
VMRVNAPD07 EDT07:NO ALARM
VMRVNAPD08 EDT08:NO ALARM
VMRVNAPD09 EDT09:NO ALARM
VMRVNAPD10 EDT10:NO ALARM
VMRVNAPD11 EDT11:NO ALARM
VMRVNAPD12 EDT12:NO ALARM
VMRVNAPD13 EDT13:NO ALARM
VMRVNAPD14 EDT14:NO ALARM
VMRVNAPD15 EDT15:NO ALARM
VMRVNAPD16 EDT16:NO ALARM
VMRVNAPD28 EDT28:NO ALARM

Personal Notification Manager

Access Manager
VMRVNAPD17 AM01: NO ALARM
VMRVNAPD18 AM02: RAISED ALARM SFTP at 0332

Messaging Server
VMRVNAPD30 MSVM01: NO ALARM
VMRVNAPD31 MSVM02: NO ALARM
VMRVNAPD37 MSVM03: NO ALARM
VMRVNAPD40 MSVM04: NO ALARM

ベストアンサー1

おすすめ記事