#!/bin/bash

IP=192.168.1.1;
log="ping_$IP";

# Infinite loop
while(true)
do
        # Send 1 ICMP Packet.
        ping -c 1 $IP > /dev/null;

        # $? return "ping" command successful or not.
        # 1 is failure and 0 is successful.
        if [ $? -eq 1 ]; then
                # log the failure time.
                echo `date +"%Y/%m/%d %H:%M:%S"` " ping $IP is failure." >> $log;
        fi
        sleep 1;
done

arrow
arrow
    全站熱搜

    dreamtails 發表在 痞客邦 留言(0) 人氣()