Simple up check of ip address
This script simply pings the given ip-address and every time there is a change in response status it shows the date and the status. This is nice to keep track of conections that flap a lot.#!/bin/bashif [ "$#" -ne 1 ]; then echo "Usage: $0 <host>" exitfiHOST=$1trap ctrl_c INTfunction ctrl_c() { echo echo "$STATUS $DATE, $HOST: Total=$totalCount, Errors=$errorCount => $errorPercentage% failed" exit}totalCount=0errorCount=0previousPingStatus=-1while [ 1 ]; do totalCount=$(( $totalCount + 1 )) ping -c 1 -W 1 -q $HOST > /dev/null pingStatus=$? if [ $pingStatus -ne 0 ]; then errorCount=$(( $errorCount + 1 )) fi errorPercentage=$(( $errorCount * 100 / $totalCount )) DATE=`date +%Y-%m-%d %H:%M` if [ $previousPingStatus -ne $pingStatus ]; then STATUS="ERROR" if [ $pingStatus -eq 0 ]; then STATUS="OK " fi echo "$STATUS $DATE, $HOST: Total=$totalCount, Errors=$errorCount => $errorPercentage% failed" fi previousPingStatus=$pingStatus if [ $pingStatus -eq 0 ]; then sleep 1 fidone