Shell script for checking if a static ip is active
I have prepared a shell script to check whether a static ip is active or not
cat > check-ip-up.sh
#!/bin/bash
IP1=’static-ip1'
IP2=’static-ip2'
IP3=’static-ip3'
/sbin/fping -c1 -t300 $IP1 2>/dev/null 1>/dev/null
a=$?/sbin/fping -c1 -t300 $IP2 2>/dev/null 1>/dev/null
b=$?/sbin/fping -c1 -t300 $IP3 2>/dev/null 1>/dev/null
c=$?if [ “$a” = “0” ] || [ “$b” = “0” ] || [“$c” = “0”]
then
if [ -e /home/somefile.txt ]
then
echo “con1,con2 and con3 are up” | mail -s “Internet connection up” <yourmail@example.com>
/bin/rm /home/somefile.txt # If connection is up, removes the empty file.In this way you know if connection is up
else
exit 0
fi
else
if [ -e /home/somefile.txt ]
then
exit 0
else
/bin/touch /home/somefile.txt # If connection is down, creates a empty file
echo “con1,con2 and con3 are down” | mail -s “Internet connection down” <yourmail@example.com>
fi
fi
ctrl+d (To save the script)
chmod +x check-ip.sh
Add the script in crontab
*/10 * * * * /usr/bin/bash /home/check-ip-up.sh >/dev/null 2>&1
This shell script will inform you if the static ip (Wifi connections) is down or up.