监控服务状态脚本(OA,电话外呼系统)

cat check_port.sh
#!/bin/bash
ERR_FILE=/root/shell/err.txt
OK_FILE=/root/shell/ok.txt
MAIL_LIST_ALL=liu@163.com,wm@163.com,qiao@163.com
MAIL_LIST_TEST=liu@163.com,wm@163.com
cat /root/shell/ip.txt|while read line
do
/usr/bin/nc -w 1 -z $line > /dev/null 2>&1
if [ $? -eq 0 ]
then
echo "$(date +%F-%H:%M:%S) telnet $line ok" >> ${OK_FILE}
#mail -s "192.168.1.5 down" $MAIL_LIST_ALL < /root/shell/err.txt
sleep 1
else
echo "$(date +%F-%H:%M:%S) telnet $line fail" >> ${ERR_FILE}
#mail -s "192.168.1.5 down" $MAIL_LIST_ALL < /root/shell/err.txt
echo "$(date +%F-%H:%M:%S) telnet $line fail" | mail -s "192.168.1.5 donw" $MAIL_LIST_ALL
#echo "$line Port down" | ${CMD_MAIL} -s "$line services port down" ${MAIL_LIST}
fi
done

 

cat ip.txt
192.168.1.5 3389
192.168.2.68 6688

posted @ 2023-12-11 17:01  miclesvic  阅读(8)  评论(0编辑  收藏  举报