最近有這樣一個需求,需要知道目標機器是否是live狀態,通過腳本發送ping其實是一個最原始的辦法,一般情況不推薦使用,以下是實現思路。
#!/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