Created
August 21, 2017 21:38
-
-
Save jfach/0a7e7d1fa2520e491f4d0fefa9b15519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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