{"id":3189,"date":"2019-08-15T09:33:16","date_gmt":"2019-08-15T01:33:16","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=3189"},"modified":"2019-08-15T09:33:16","modified_gmt":"2019-08-15T01:33:16","slug":"linux-shell-script-check-usb-device-%e9%80%8f%e9%81%8eshell-script%e5%88%a4%e6%96%b7usb%e8%a8%ad%e5%82%99%ef%bc%8c%e5%9f%b7%e8%a1%8c%e7%89%b9%e5%ae%9a%e7%a8%8b%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=3189","title":{"rendered":"[ LINUX ] &#8211; Shell Script Check USB Device \u900f\u904eShell Script\u5224\u65b7usb\u8a2d\u5099\uff0c\u57f7\u884c\u7279\u5b9a\u7a0b\u5f0f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u5de5\u4f5c\u4e0a\u9700\u8981\u5224\u65b7\u662f\u5426\u6709\u63d2\u5165\u96a8\u8eab\u789f\uff0c\u6307\u4ee4\u9084\u6eff\u7c21\u55ae\u7684\u6240\u4ee5\u518d\u767c\u60f3\u4e00\u4e9b\u61c9\u7528\u9762\u7684\u6771\u897f\uff1b\u5305\u542b\u7c21\u55ae\u7684 shell script \u53bb\u57f7\u884c\u6307\u5b9a\u7a0b\u5f0f\u3002<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u6307\u4ee4\uff1alsusb<br \/>\nBus 001 Device 002: ID 8087:8001 Intel Corp. <br \/>\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br \/>\nBus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub<br \/>\nBus 002 Device 006: ID 0bda:8821 Realtek Semiconductor Corp. <br \/>\nBus 002 Device 004: ID 0518:0001 EzKEY Corp. USB to PS2 Adaptor v1.09<br \/>\nBus 002 Device 003: ID 05e3:0727 Genesys Logic, Inc. microSD Reader\/Writer<br \/>\nBus 002 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse<br \/>\nBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br \/>\n\u8aaa\u660e\uff1a\u6703\u5217\u51fa\u76ee\u524d\u6240\u6709\u9023\u4e0ausb\u8a2d\u5099<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u63d2\u5165usb\u96a8\u8eab\u789f \u518d\u57f7\u884c\u4e00\u6b21\u6307\u4ee4<br \/>\n\u6307\u4ee4\uff1alsusb<br \/>\nBus 001 Device 002: ID 8087:8001 Intel Corp. <br \/>\nBus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br \/>\nBus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub<br \/>\nBus 002 Device 006: ID 0bda:8821 Realtek Semiconductor Corp. <br \/>\nBus 002 Device 018: ID 1005:b113 Apacer Technology, Inc. Handy Steno\/AH123 \/ Handy Steno 2.0\/HT203<br \/>\nBus 002 Device 004: ID 0518:0001 EzKEY Corp. USB to PS2 Adaptor v1.09<br \/>\nBus 002 Device 003: ID 05e3:0727 Genesys Logic, Inc. microSD Reader\/Writer<br \/>\nBus 002 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse<br \/>\nBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br \/>\n\u8aaa\u660e\uff1a\u6703\u767c\u73fe\u63d2\u5165usb\u5f8c\u591a\u4e86\u4e00\u884c<br \/>\nBus 002 Device 018: ID 1005:b113 Apacer Technology, Inc. Handy Steno\/AH123 \/ Handy Steno 2.0\/HT203<br \/>\n\u53ef\u4ee5\u767c\u73fe\u65b0\u589e\u7684\u4e00\u884c\u5c31\u662f\u525b\u63d2\u5165\u7684usb\u54c1\u724c Apacer<br \/>\n\u9019\u908a\u5148\u8a18\u4e0b\u8a72usb\u7684ID 1005:b113<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u589e\u4e00\u500b\u6587\u6a94\uff0c\u547d\u540d\u70ba checkusb.sh<br \/>\n\u6587\u4ef6\u5167\u5bb9\u5982\u4e0b<\/p>\n\n\n<p class=\"wp-block-paragraph\">!\/bin\/sh<br \/>lsusb | grep 1005:b113 &gt;\/dev\/null<br \/> if [ $? -eq 0 ]<br \/> then<br \/> echo &#8220;Connection&#8221;<br \/> else<br \/> echo &#8220;Broken&#8221;<br \/> fi<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u8aaa\u660e\uff1a<\/p>\n\n\n<p class=\"wp-block-paragraph\">!\/bin\/sh =&gt;\u4f7f\u7528shell script\u4f86\u57f7\u884c\u8a72\u7a0b\u5f0f<br \/>lsusb | grep 1005:b113 &gt;\/dev\/null =&gt;lsusb \u900f\u904e\u6587\u5b57\u904e\u6ffe\u51fa \u6307\u5b9a\u7684usb id<br \/> if [ $? -eq 0 ] =&gt; \u5982\u679c\u6709\u627e\u5230\u8a72id<br \/> then<br \/> echo &#8220;Connection&#8221;=&gt;\u5c31\u8f38\u51fa Connection <br \/> else<br \/> echo &#8220;Broken&#8221;=&gt;\u6c92\u627e\u5230 \u5c31\u8f38\u51fa Broken<br \/> fi =&gt;\u7d50\u675f\u8a9e\u53e5<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4e2decho &#8220;Connection&#8221; \u53ef\u4ee5\u66ff\u63db\u6210\u4f60\u60f3\u8981\u57f7\u884c\u7684\u5176\u5b83\u7a0b\u5f0f \u53ef\u4ee5\u662f.sh \/ java \/ php \/ .py \u7b49\u7b49\u2026<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u6700\u5f8c\u767c\u60f3\u4e00\u4e0b\u61c9\u7528\uff0c\u5982\u679c\u4f60\u6709\u4e9b\u7a0b\u5f0f\u6709\u4e9b\u5b89\u5168\u6027\u7684\u6a5f\u5236\uff0c\u4f60\u5c31\u53ef\u4ee5\u8acb\u4f7f\u7528\u8005\u63d2\u5165\u6307\u5b9a\u7684usb\u96a8\u8eab\u789f\u7576\u9470\u5319\uff0c\u7c21\u55ae\u4e00\u9ede\u7684\u65b9\u6cd5\u5c31\u5982\u540c\u4e0a\u9762\uff0c\u8907\u96dc\u4e00\u9ede\u7684\u65b9\u5f0f\u5c31\u53ef\u4ee5\u52a0\u5165\u516c\u79c1\u9470\u7684\u8a08\u7b97\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t\u6700\u8fd1\u5de5\u4f5c\u4e0a\u9700\u8981\u5224\u65b7\u662f\u5426\u6709\u63d2\u5165\u96a8\u8eab\u789f\uff0c\u6307\u4ee4\u9084\u6eff\u7c21\u55ae\u7684\u6240\u4ee5\u518d\u767c\u60f3\u4e00\u4e9b\u61c9\u7528\u9762\u7684\u6771\u897f\uff1b\u5305\u542b\u7c21\u55ae\u7684 shell script \u53bb\u57f7\u884c\u6307\u5b9a\u7a0b\u5f0f\u3002\t\t<\/p>\n","protected":false},"author":1,"featured_media":3618,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[158,511,591],"class_list":["post-3189","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-check-usb-device","tag-shell-script","tag-usb","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3189"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3189\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/3618"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}