[root@localhost root]# vi ping003.sh
#!/bin/bash
date1=$(date +%Y%m%d)
x=1
HOST="10.1.1.200"
while [ "${x}" != "8400" ]
do
count=$(ping -c 1 -n -W 3 $HOST | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
echo "$(date +'%Y%m%d %T') $HOST is down" >> /root/ping_$date1.log
else
echo "$(date +'%Y%m%d %T') $HOST is up" >> /root/ping_$date1.log
sleep 3
fi
x=$(($x+1))
done
[root@localhost root]# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.30959 installed on Fri Mar 31 16:44:34 2017)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# Monitor remote host every 1 minutes using /root/ping001.sh
0 8 * * * /root/ping003.sh
沒有留言:
張貼留言