{"id":1113,"date":"2019-01-31T14:16:25","date_gmt":"2019-01-31T06:16:25","guid":{"rendered":"http:\/\/van-yzt.com\/?p=1113"},"modified":"2019-01-31T14:16:25","modified_gmt":"2019-01-31T06:16:25","slug":"tcl-expect","status":"publish","type":"post","link":"https:\/\/huzi-baozi.com\/?p=1113","title":{"rendered":"TCL Expect"},"content":{"rendered":"<pre><code class=\"language-Shell\">#!\/usr\/bin\/expect -f\n\nproc terminal:password:get {promptString} {\n\n     # Turn off echoing, but leave newlines on.  That looks better.\n     # Note that the terminal is left in cooked mode, so people can still use backspace\n     exec stty -echo echonl &lt;@stdin\n\n     # Print the prompt\n     puts -nonewline stdout $promptString\n     flush stdout\n\n     # Read that password!  :^)\n     gets stdin password\n\n     # Reset the terminal\n     exec stty echo -echonl &lt;@stdin\n\n     return $password\n}\n\nproc chooseMachine { } {\n    puts &quot;1) 11.192.101.216 (pre\/ccvob);\\n2) 11.192.101.192;\\n3) 11.192.101.236;\\n4) 11.192.101.221;&quot;;\n    gets stdin choice;\n    switch $choice {\n        1 {\n            return &quot;11.192.101.216&quot;;\n        }\n        2 {\n            return &quot;11.192.101.192&quot;;\n        }\n        3 {\n            return &quot;11.192.101.236&quot;;\n        }\n        4 {\n            return &quot;11.192.101.221&quot;;\n        }\n        default {\n            return &quot;11.192.101.216&quot;;\n        }\n    }\n}\n\nproc main { } {\n    set timeout -1;\n    set IP [ chooseMachine ];\n    set PASSWORD [ terminal:password:get &quot;\u8bf7\u8f93\u5165\u5bc6\u7801:&quot; ];\n    puts &quot;Start build source success&quot;;\n    spawn ssh van.yzt@11.239.182.250;\n    expect &quot;*password:&quot;;\n    send &quot;$PASSWORD\\r&quot;;\n    expect &quot;*$*&quot;;\n    set TOKEN [ terminal:password:get &quot;\u8bf7\u8f93\u51656\u4f4d\u4ee4\u724c:&quot; ];\n    spawn ssh van.yzt@login1.am100.alibaba-inc.com;\n    expect &quot;*password*&quot;;\n    send &quot;$PASSWORD$TOKEN\\r&quot;;\n    expect &quot;*$*&quot;;\n    send &quot;ssh van.yzt@$IP\\r&quot;;\n    expect &quot;password:&quot;;\n    send &quot;$PASSWORD\\r&quot;;\n    expect &quot;*$*&quot;;\n    send &quot;sudo su admin\\r&quot;;\n    expect &quot;*password*&quot;;\n    send &quot;$PASSWORD\\r&quot;;\n    expect &quot;*$*&quot;;\n    interact;\n    exit 0;\n}\n\n[ main ];\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/expect -f proc terminal:password:get {promptString} { # Turn off echoing, but leave newlines on. That looks better. # Note that the terminal is left in cooked mode, so people can still use backspace exec stty -echo echonl &lt;@stdin # Print the prompt puts -nonewline stdout $promptString flush stdout # Read that password! :^) gets stdin &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/huzi-baozi.com\/?p=1113\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;TCL Expect&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1113","post","type-post","status-publish","format-standard","hentry","category-snippet"],"_links":{"self":[{"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/posts\/1113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1113"}],"version-history":[{"count":1,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/posts\/1113\/revisions"}],"predecessor-version":[{"id":1114,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=\/wp\/v2\/posts\/1113\/revisions\/1114"}],"wp:attachment":[{"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huzi-baozi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}