To detect if there is a link or not on network interface without any physical intervention, simply run the following command :
cat /sys/class/net/<interface_name>/carrier
This command should return ” 0 ” or ” 1 “. Of course, 0 mean disconnected and 1 connected.