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
tail -f /var/log/syslog | grep -E 'link (up|down)'
or for me faster gets:
tail -f /var/log/syslog | grep 'link \(up\|down\)'
It will listen to the syslog file.
Result (if disconnect and after 4 seconds connect again):
Jan 31 13:21:09 user kernel: [19343.897157] r8169 0000:06:00.0 enp6s0: link down
Jan 31 13:21:13 user kernel: [19347.143506] r8169 0000:06:00.0 enp6s0: link up