Script to check NIC up or down

Many time we do face the issue on our servers that secondary or other NIC’S on server was down because of that domains or application hosted on that particular NIC was down, therefore to avoid such problem, we have written a script which will monitor the NIC uptime and get it up, if NIC found out down, you can refer to the following steps and add the script as per your requirement.

Login into the server as root user and check the NIC number under which you are facing an issue, for example, we are facing an issue with eth0:1, therefore we have defined eth0:1 in the script, you can change the NIC number as per your requirement.

#!/bin/bash
echo “ifconfig testing manually”;
if
[ $(ifconfig | grep ‘eth0:1’ | grep -v grep | wc -l | tr -s “\n”) -eq 0 ];
then
echo “Service is down and require restart”;
ifup eth0:1;
fi

You can set the cron, so that script will run after every minute or as per your requirement and get down NIC up and running without your manual monitoring.

 

 

About Anant 384 Articles
Senior technical writer