In a Linux environment, I need to detect the physical connected or disconnected state of an RJ45 connector to its socket. Preferably using BASH scripting only.
The
On OpenWRT the only way to reliably do this, at least for me, is by running these commands:
# Get switch name
swconfig list
# assuming switch name is "switch0"
swconfig dev switch0 show | grep link:
# Possible output
root@OpenWrt:~# swconfig dev switch0 show | grep link:
link: port:0 link:up speed:1000baseT full-duplex txflow rxflow
link: port:1 link:up speed:1000baseT full-duplex txflow rxflow eee100 eee1000 auto
link: port:2 link:up speed:1000baseT full-duplex txflow rxflow eee100 eee1000 auto
link: port:3 link:down
link: port:4 link:up speed:1000baseT full-duplex eee100 eee1000 auto
link: port:5 link:down
link: port:6 link:up speed:1000baseT full-duplex txflow rxflow
This will show either "link:down" or "link:up" on every port of your switch.