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

相关内容