#!/bin/bash i=0 j=0 subject="web1 80 端口狀態監控" messagelog="web1 80 端口測試成功!!" messagelog1="web1 80 端口測試不成功!!" while [[ $i -le 10 ]] do i=$((${i}+1)) nc -z -w 1 172.20.101.54 80 >/usr/local/monitor/test.txt b=`cat test.txt|grep succeeded|wc -l` if [ $b -ne 0 ]; then j=$((${j}+1)) else exit 0 fi done if [ $j -ge 9 ]; then /usr/local/bin/sendEmail -s 172.20.101.63 -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com -u "$su bject" -m "$messagelog" else /usr/local/bin/sendEmail -s 172.20.101.63 -xu admin@huiyewang.com -xp 1234565 -f admin@huiyewang.com -t monitor@huiyewang.com -u "$su bject" -m "$messagelog1" fi