Simple bash script for check network link status

Linuxtopic
1



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 ethtool 

Create 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












Post a Comment

1Comments

  1. They have decided to make this group to pay practically all master SEO prerequisites anyway they besides market the specific each product application autonomously.
    https://ryancameron.me

    ReplyDelete
Post a Comment

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Ok, Go it!