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
I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. cctv installation companies
ReplyDeleteThanks for sharing this blog you can also visit https://connectmyprinter.com/
ReplyDeleteVery useful info. Hope to see more posts soon!. voice data cabling
ReplyDeleteGreat things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks network cabling installation
ReplyDeleteYou wrote this post very carefully.Network Cabling Services The amount of information is stunning and also a gainful article for us. Keep sharing this kind of articles, Thank you.
ReplyDeleteThey have decided to make this group to pay practically all master SEO prerequisites anyway they besides market the specific each product application autonomously.
ReplyDeletehttps://ryancameron.me