Skip to content

Instantly share code, notes, and snippets.

@jfach
Created August 21, 2017 21:38
Show Gist options
  • Save jfach/0a7e7d1fa2520e491f4d0fefa9b15519 to your computer and use it in GitHub Desktop.
Save jfach/0a7e7d1fa2520e491f4d0fefa9b15519 to your computer and use it in GitHub Desktop.
#! /bin/bash
if [ -e /tmp/ping-test.pid ]
then
echo "script already running"
exit 1;
fi
PID=$$
HOST=$1
COUNTER=0
echo $PID >> /tmp/ping-test.pid
while [ $COUNTER -lt 5 ];
do
let COUNTER+=1
ping -c1 $HOST
if [ $? -eq 0 ]
then
echo "OK"
rm /tmp/ping-test.pid
exit 0
else
echo "ERROR"
sleep 1
fi
done
echo "FAIL"
rm /tmp/ping-test.pid
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment