Shell script for checking if a static ip is active

SebinnSebastian
1 min readJul 6, 2022

--

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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

SebinnSebastian
SebinnSebastian

Written by SebinnSebastian

DevOps Engineer | Redhat Certified System Administrator | K8s Administrator | AWS, Docker, Terraform, GCP

No responses yet

Write a response