1. 개요
ping 확인 → fail시 list 작성 → 메일 전송
2. Source Code
#!/bin/sh
LOG_DIR="/home/tuser/log/ping.log"
echo "===== 서버 점검 결과 (`date '+%F %T'` 기준) =====\n"
email="tuser@ubuntu"
for host in $(cut -d: -f1 ./serverIP.lst)
do
host_ip=`grep $host ./serverIP.lst | cut -d: -f2`
if ! ping -c 1 $host_ip >> /dev/null; then
sleep 1
if ! ping -c 1 $host_ip >> /dev/null; then
echo "\n* $host 서버 : 점검 요망"
echo "\n* $host 서버 : 점검 요망 " >> $LOG_DIR
fi
fi
done
if [ -s /home/tuser/log/ping.log ]; then
mail -s "서버 점검 결과입니다. `date '+%F %T'` 기준" $email < $LOG_DIR
fi
echo "\n======================================"
rm -f $LOG_DIR
exit