̽Ë÷ Linux linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔ
̽Ë÷ Linux Linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔ
ÔÚ Linux ϵͳÖУ¬Linkwatch ÊÇÒ»¸öÖ÷ÒªµÄÀú³Ì£¬ÈÏÕæ¼à¿ØÍøÂçÁ´Â·µÄת±ä²¢×÷³öÏìÓ¦µÄ´¦Öóͷ£¡£Linkwatch Àú³ÌµÄ±£´æ£¬¿ÉÒÔ×ÊÖúϵͳʵʱ·¢Ã÷ÍøÂçÁ´Â·µÄת±ä£¬ÈçÍø¿¨¶Ï¿ª»òÅþÁ¬¡¢IP µØµãת±äµÈÇéÐΣ¬´Ó¶øÌá¸ßϵͳµÄÍøÂçÎȹÌÐԺͿɿ¿ÐÔ¡£±¾ÎĽ«ÉîÈë̽ÌÖ Linux Linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔ£¬²¢Í¨¹ýÏêϸ´úÂëʾÀýÀ´Õ¹Ê¾ÆäÊÂÇéÔÀí¡£
Ò»¡¢Linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔ
1.1 ÓÃ;£º
Linkwatch Àú³ÌÖ÷ÒªÓÃÓÚ¼à¿ØÍøÂçÁ´Â·µÄ״̬ת±ä¡£ÔÚÒ»¸öÖØ´óµÄÍøÂçÇéÐÎÖУ¬ÍøÂçÁ´Â·³£³£»á±¬·¢×ª±ä£¬ÈçÍø¿¨¶Ï¿ª¡¢ÖØÐÂÅþÁ¬¡¢IP µØµãת±äµÈ¡£ÕâЩת±ä»áÓ°ÏìϵͳµÄÍøÂçÅþÁ¬ºÍͨѶ£¬Òò´ËÐèÒªÒ»¸öרÃŵÄÀú³ÌÀ´¼à¿ØÍøÂçÁ´Â·×´Ì¬£¬²¢ÊµÊ±×÷³öÏìÓ¦µÄ´¦Öóͷ£¡£
1.2 Ö÷ÒªÐÔ£º
Linkwatch Àú³ÌµÄÖ÷ÒªÐÔÔÚÓÚÌá¸ßϵͳµÄÍøÂçÎȹÌÐԺͿɿ¿ÐÔ¡£Í¨¹ý¼à¿ØÍøÂçÁ´Â·×´Ì¬£¬Linkwatch Äܹ»ÊµÊ±·¢Ã÷ÍøÂçÁ´Â·µÄת±ä£¬²¢Í¨ÖªÏµÍ³×ö³öÏìÓ¦µÄµ÷½â¡£ÀýÈ磬ÔÚÍø¿¨¶Ï¿ªÊ±£¬Linkwatch ¿ÉÒÔ֪ͨϵͳ×èÖ¹¶Ô¸ÃÍø¿¨µÄÊý¾Ý´«Êä²Ù×÷£¬×èÖ¹Êý¾Ýɥʧ£»ÔÚÍøÂçÖØÐÂÅþÁ¬Ê±£¬Linkwatch ¿ÉÒÔÖØн¨ÉèÍøÂçÅþÁ¬£¬È·±£ÍøÂçͨѶÁ÷ͨ¡£
¶þ¡¢Ïêϸ´úÂëʾÀý
ÏÂÃæÒÔÒ»¸ö¼òÆÓµÄʾÀýÀ´ÑÝʾÔõÑùʹÓà Linkwatch Àú³ÌÀ´¼à¿ØÍøÂçÁ´Â·µÄ״̬ת±ä¡£¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪ linkwatch.sh µÄ¾ç±¾£¬ÓÃÓÚ¼à¿ØÍøÂçÁ´Â·µÄת±ä¡£
#!/bin/bash # ¼à¿ØÍøÂçÁ´Â·×´Ì¬×ª±ä while true do LINK=$(cat /sys/class/net/eth0/carrier) if [ $LINK -eq 0 ] then echo "Ethernet link is down" else echo "Ethernet link is up" fi sleep 1 done
µÇ¼ºó¸´ÖÆ
ÔÚÕâ¸öʾÀýÖУ¬ÎÒÃÇʹÓÃÒ»¸ö while Ñ»·À´Ò»Á¬¼à¿ØÃûΪ eth0 µÄÍø¿¨µÄÁ´Â·×´Ì¬¡£Í¨¹ý¶ÁÈ¡ /sys/class/net/eth0/carrier ÎļþµÄÄÚÈÝ£¬ÎÒÃÇ¿ÉÒÔ»ñÈ¡Íø¿¨µÄÁ´½Ó״̬¡£ÈôÊÇÁ´½Ó״̬Ϊ 0£¬ÌåÏÖÍø¿¨¶Ï¿ª£»ÈôÊÇÁ´½Ó״̬Ϊ 1£¬ÌåÏÖÍø¿¨ÅþÁ¬Õý³£¡£Æ¾Ö¤»ñÈ¡µ½µÄ״̬£¬ÎÒÃÇ¿ÉÒÔÔھ籾ÖÐ×÷³öÏìÓ¦µÄ´¦Öóͷ£¡£
Èý¡¢×ܽá
×ܵÄÀ´Ëµ£¬Linux Linkwatch Àú³ÌÔÚϵͳµÄÍøÂçÖÎÀíÖÐÊÎÑÝ×ÅÖ÷ÒªµÄ½ÇÉ«¡£Í¨¹ý¼à¿ØÍøÂçÁ´Â·µÄת±ä£¬Linkwatch Àú³Ì¿ÉÒÔ×ÊÖúϵͳʵʱ·¢Ã÷ÍøÂçÎÊÌâ²¢×÷³öÏìÓ¦µÄ´¦Öóͷ££¬Ìá¸ßϵͳµÄÍøÂçÎȹÌÐԺͿɿ¿ÐÔ¡£Í¨¹ý±¾ÎĵÄÏÈÈݺÍÏêϸ´úÂëʾÀý£¬ÐÅÍжÁÕß¶Ô Linux Linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔÓÐÁ˸üÉîÈëµÄÏàʶºÍÊìϤ¡£
ÒÔÉϾÍÊÇ̽Ë÷ Linux linkwatch Àú³ÌµÄÓÃ;ºÍÖ÷ÒªÐÔµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡