Simple bash script for check network link status
This is simple bash script to check network interface link status we used a if else condition in this script. if network cable not plug shell script will echo disconnected else echo connected.
In Hindi
In English
Step 1:
install ethtool package
apt-get install ethtoolCreate a file in /usr/local/bin or any other location with following script
vi /usr/local/bin/status
#!/bin/bash
# Bash script created by lokesh
# For loop start
for status in eth0 eth1 wlan0 wlan1 wlan2 wlan3
do
# if condition start
if [[ ! $( ethtool $status | grep -i "Link detected: yes" ) ]]; then
echo "$status Disconnected"
else
echo "$status Connected"
# if condition end
fi
# for loop end
done;
Explanation :
For loop :
for status in eth0 eth1 wlan0 wlan1 wlan2 wlan3
do
check interface step by step in loop, you can use your interface by replace all
if else :
if [[ ! $( ethtool $status | grep -i "Link detected: yes" ) ]]; then
for check condition true or false
ethtool = command
$status = loop variable
grep -i "Link detected: yes" = grep ethtool outupt
Thanks
Leave a Comment