Skip to content

Instantly share code, notes, and snippets.

@dbalan
Last active December 12, 2015 08:28
Show Gist options
  • Save dbalan/4743794 to your computer and use it in GitHub Desktop.
Save dbalan/4743794 to your computer and use it in GitHub Desktop.
Tests pings.
#!/bin/bash
if [ $# != 2 ]; then
echo "USAGE: " ${0}" ip-addr warning-level" ;
exit;
fi
timeout 3 ping -c 1 $1 > /tmp/out
if [ $? -ne 0 ]; then
echo "CRITICAL -"${1}" is DOWN’"
exit -1
else
delay=$(grep time /tmp/out |head -n -1|awk '{print $7}'|cut -d = -f2)" ms"
if [[ $delay > $2 ]]; then
delay=$delay"> "$2
echo -n "WARNING"
else
echo -n "OK"
fi
echo "-"" " ${1} " is UP - Delay" $delay
rm /tmp/out
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment