{"id":498,"date":"2018-10-26T16:09:00","date_gmt":"2018-10-26T07:09:00","guid":{"rendered":"https:\/\/wp.zassoul.com\/?p=498"},"modified":"2018-10-26T16:09:00","modified_gmt":"2018-10-26T07:09:00","slug":"expect%e3%82%b3%e3%83%9e%e3%83%b3%e3%83%89%e3%81%a7teraterm-macro%e3%81%ae%e3%82%88%e3%81%86%e3%81%aa%e3%81%93%e3%81%a8%e3%82%92%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/wp.zassoul.com\/?p=498","title":{"rendered":"expect\u30b3\u30de\u30f3\u30c9\u3067teraterm macro\u306e\u3088\u3046\u306a\u3053\u3068\u3092\u3059\u308b"},"content":{"rendered":"<p>Win10\u306bWSL\u306eUbuntu 18.0.4\u5165\u308c, bash\u304b\u3089\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u63a5\u7d9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305f\u3002<br \/><a href=\"https:\/\/zassoul.blogspot.com\/2018\/10\/linux-os.html\" target=\"_blank\" rel=\"noopener noreferrer\">Linux OS\u3067\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u63a5\u7d9a<\/a><br \/>\u6b21\u306f\u4e00\u9023\u306e\u30b3\u30de\u30f3\u30c9\u51e6\u7406\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u81ea\u52d5\u5316\u3055\u305b\u308b\u3002<\/p>\n<p>\u300cexpect\u300d \u30b3\u30de\u30f3\u30c9\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u3044\u3066\u3044\u304f\u3002<br \/>\u524d\u63d0\u6761\u4ef6\u306f<br \/>\u30fc Cisco\u6a5f\u5668\u306f\u30e6\u30fc\u30b6\u540d\/\u30d1\u30b9\u30ef\u30fc\u30c9\u7b49\u57fa\u672c\u8a2d\u5b9a\u306f\u5b8c\u4e86\u6e08\u307f<br \/>\u30fc \u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306f \/dev\/ttyS2 \u3092\u5229\u7528<br \/>\u30fc \u63a5\u7d9a\u30b3\u30de\u30f3\u30c9\u306f cu \u30b3\u30de\u30f3\u30c9\u3092\u5229\u7528<\/p>\n<pre>#!\/bin\/sh<br \/><br \/>expect -c \"<br \/>set timeout 10                            # \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u8a2d\u5b9a\uff1a10\u79d2<br \/>spawn cu -l \/dev\/ttyS2                    # \u5b9f\u884c\u30b3\u30de\u30f3\u30c9\u8a18\u8ff0<br \/>sleep 2                                   # 2\u79d2\u5f85\u3061\u3092\u5165\u308c\u308b\u3002\u3053\u308c\u3092\u5165\u308c\u306a\u3044\u3068\u3046\u307e\u304f\u30b3\u30f3\u30bd\u30fc\u30eb\u304c\u958b\u59cb\u3057\u306a\u3044<br \/>send \"n\"                               # Enter\u30ad\u30fc\u3067Cisco\u306e\u30bf\u30fc\u30df\u30ca\u30eb\u3092\u8868\u793a\u3055\u305b\u308b<br \/>expect \"Username:\"                      # \u30e6\u30fc\u30b6\u540d\u5165\u529b\u30e1\u30c3\u30bb\u30fc\u30b8\u5f85\u3061<br \/>send \"usernamen\"                       # \u30e6\u30fc\u30b6\u540d\u3092\u5165\u529b<br \/>expect \"Password:\"                      # \u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u30e1\u30c3\u30bb\u30fc\u30b8\u5f85\u3061<br \/>send \"passwordn\"                       # \u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5165\u529b<br \/>expect \"&gt;\"                              # \u30d7\u30ed\u30f3\u30d7\u30c8\u5f85\u3061<br \/>send \"enn\"                             # enable\u30b3\u30de\u30f3\u30c9\u5165\u529b<br \/>expect \"Password:\"                      # \u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u30e1\u30c3\u30bb\u30fc\u30b8\u5f85\u3061<br \/>send \"enablen\"                         # enable\u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b<br \/>expect \"#\"                             # \u7279\u6a29\u30e2\u30fc\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u5f85\u3061<br \/>send \"term leng 0 n\"                   # \u51e6\u74061 (\u4eca\u56de\u306f terminal length 0)<br \/>expect \"#\"                             # \u7279\u6a29\u30e2\u30fc\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u5f85\u3061<br \/>send \"show run n\"                      # \u51e6\u74062 (\u4eca\u56de\u306f show run)<br \/>expect \"#\"                             # \u7279\u6a29\u30e2\u30fc\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u5f85\u3061<br \/>send \"exit n\"                          # \u51e6\u7406\u7d42\u4e86<br \/>expect \"Press RETURN to get started.\"   # \u30ed\u30b0\u30a2\u30a6\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8\u5f85\u3061<br \/>exit 0                                    # \u30b9\u30af\u30ea\u30d7\u30c8\u7d42\u4e86<br \/>\"<br \/><\/pre>\n<p>\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067show running-config\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/># screen\u30b3\u30de\u30f3\u30c9\u3067\u3084\u308b\u5834\u5408\u306froot\u6a29\u9650\u304c\u5fc5\u8981\u306a\u306e\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306fsudo \u3067\u3084\u308b\u3002<br \/>teraterm macro \u3067\u3084\u308b\u3053\u3068\u3068\u307b\u307c\u540c\u3058\u3053\u3068\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3084\u3063\u3066\u3044\u308b\u3060\u3051\u3060\u3051\u308c\u3069, \u3053\u308c\u304c\u3067\u304d\u308b\u3068\u6b21\u306b\u3084\u3063\u3068Ansible\u3092\u7d61\u3081\u305f\u30b3\u30f3\u30bd\u30fc\u30eb\u7d4c\u7531\u3067\u306e\u51e6\u7406\u81ea\u52d5\u5316\u306b\u9032\u3081\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Win10\u306bWSL\u306eUbuntu 18.0.4\u5165\u308c, bash\u304b\u3089\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u63a5\u7d9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u305f\u3002Linux OS\u3067\u30b7\u30ea\u30a2\u30eb\u30b3\u30f3\u30bd\u30fc\u30eb\u63a5\u7d9a\u6b21\u306f\u4e00\u9023\u306e\u30b3\u30de\u30f3\u30c9\u51e6\u7406\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u81ea\u52d5\u5316\u3055\u305b\u308b\u3002 \u300cexpect\u300d \u30b3\u2026 <span class=\"read-more\"><a href=\"https:\/\/wp.zassoul.com\/?p=498\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,13,15,8],"tags":[],"class_list":["post-498","post","type-post","status-publish","format-standard","hentry","category-cisco","category-linux","category-network","category-8"],"_links":{"self":[{"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=\/wp\/v2\/posts\/498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=498"}],"version-history":[{"count":0,"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=\/wp\/v2\/posts\/498\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.zassoul.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}