最近有這樣一個(gè)需求,需要知道目標(biāo)機(jī)器是否是live狀態(tài),通過腳本發(fā)送ping其實(shí)是一個(gè)最原始的辦法,一般情況不推薦使用,以下是實(shí)現(xiàn)思路。
#!/bin/bash
# use the script to confirm the hosts are alive or not
VIDEO_1=192.168.99.3
VIDEO_2=192.168.99.4
VIDEO_3=192.168.99.5
for LOOP in $VIDEO_1 $VIDEO_2 $VIDEO_3
do
if ! ping -c 3 $LOOP > /dev/null 2>&1; then
echo "Warning:The host $LOOP seems down" >> error.log
fi
done
if [ -f error.log ]; then
mail -s "Warning:Host Down" xiajx@hotmail.com < error.log
rm -f error.log
fi