How to detect the physical connected state of a network cable/connector?

后端 未结 15 1375
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 04:23

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

15条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 05:07

    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
    

提交回复
热议问题