\"eof\"<\/span>\n<\/code><\/pre>\n<\/p>\n\u8fd9\u4e48\u7b2c\u4e00\u6b21\u5c06\u4f1a\u6b63\u786e\u8fd0\u884c\uff0c\u7531\u4e8e\u7b2c\u4e00\u6b21sudo\u65f6\u987b\u8981\u5bc6\u7801\uff1b\u5e76\u4e14\u7b2c\u4e8c\u6b21\u8fd0\u884c\u65f6\u56e0\u4e3a\u5bc6\u7801\u65e9\u5df2\u8f93\u8fc7\uff08\u9ed8\u8ba4\u60c5\u51b5\u4e0bsudo\u5bc6\u7801\u518d\u5ea6\u8f93\u5165\u65f6\u95f4\u4e3a5\u5206\u949f\uff09\uff0c\u5219\u4e0d\u4f1a\u63d0\u793a\u7528\u6237\u53bb\u8f93\u5165\uff0c\u6240\u4ee5\u7b2c\u4e00\u4e2aexpect\u5c06\u672a\u80fd\u5339\u914d\u5230assword\uff0c\u4f46\u662f\u5fc5\u987b\u6ce8\u610f\u7684\u662f\u5047\u5982\u662fspawn\u547d\u4ee4\u51fa\u73b0\u4ea4\u4e92\u5f0f\u63d0\u95ee\u7684\u5e76\u4e14expect\u5339\u914d\u4e0d\u4e0a\u7684\u8bdd\uff0c\u8fd9\u4e48\u7a0b\u5e8f\u4f1a\u6839\u636etimeout\u7684\u8bbe\u7f6e\u8fdb\u884c\u7b49\u5f85\uff1b\u800c\u4e14\u5047\u5982spawn\u76f4\u63a5\u53d1\u51fa\u4e86eof\u4e5f\u5c31\u662f\u672c\u4f8b\u7684\u60c5\u51b5\uff0c\u8fd9\u4e48expect\"assword\"\u5c06\u4e0d\u4f1a\u7b49\u5f85\uff0c\u800c\u76f4\u63a5\u53bb\u6267\u884cexpecteof\u3002\u8fd9\u65f6\u90fd\u4f1a\u62a5expect:spawnidexp6notopen\uff0c\u7531\u4e8e\u6ca1\u6709spawn\u5728\u6267\u884c\uff0c\u65c1\u8fb9\u7684expect\u811a\u672c\u4e5f\u5c06\u4f1a\u7531\u4e8e\u8fd9\u4e2a\u7f18\u7531\u800c\u4e0d\u518d\u6267\u884c\uff1b\u6240\u4ee5\u5bf9\u4e8e\u7c7b\u4f3csudo\u8fd9\u4e9b\u547d\u4ee4\u5206\u652f\u4e0d\u5b9a\u7684\u60c5\u51b5\uff0c\u6700\u597d\u662f\u4f7f\u7528\u5e76\u884c\u7684\u5f62\u5f0f\u8fdb\u884c\u5904\u7406\uff1b<\/p>\n
\u7b2c17\u884c\uff1a\u4ec5\u4ec5\u662f\u4e00\u4e2a\u7528\u6237\u63d0\u793a\u800c\u5df2\uff0c\u53ef\u4ee5\u5220\u6389\uff1b<\/p>\n
<\/p>\n
\u7b2c18\u884c\uff1a\u5411spawn\u8fdb\u7a0b\u53d1\u9001password\uff1b<\/p>\n
\u7b2c19\u884c\uff1a\u4fc3\u4f7fspawn\u8fdb\u7a0b\u5728\u5339\u914d\u5230\u4e00\u4e2a\u540e\u518d\u53bb\u5339\u914d\u63a5\u51fa\u6765\u7684\u4ea4\u4e92\u63d0\u793a\uff1b<\/p>\n
\u7b2c21\u884c\uff1aeof\u662f\u5fc5\u987b\u53bb\u5339\u914d\u7684\uff0c\u5728spawn\u8fdb\u7a0b\u7ed3\u675f\u540e\u4f1a\u5411expect\u53d1\u9001eof\uff1b\u5018\u82e5\u4e0d\u53bb\u5339\u914d\uff0c\u6709\u65f6\u4e5f\u80fd\u8fd0\u884c\uff0c\u4f8b\u5982sleep\u591a\u5c11\u79d2\u540e\u518d\u53bbspawn\u4e0b\u4e00\u4e2a\u547d\u4ee4\uff0c\u5e76\u4e14\u4e0d\u8981\u4f9d\u8d56\u8fd9\u4e9b\u884c\u4e3a\uff0c\u5f88\u6709\u53ef\u80fd\u660e\u5929\u8fd8\u53ef\u4ee5\uff0c\u4eca\u5929\u5c31\u4e0d\u80fd\u7528\u4e86\uff1b<\/p>\n
#3<\/p>\n
\u4e0b\u8fb9\u8fd9\u4e2a\u4e8b\u4f8b\u6bd4\u8f83\u7279\u6b8a\uff0c\u5728\u6574\u4e2a\u8fc7\u7a0b\u4e2d\u5c31\u4e0d\u80fdexpecteof\u4e86\uff1a<\/p>\n
\n
#!\/usr\/bin\/expect<\/span>\nset<\/span> timeout<\/span> 30\nspawn ssh<\/span> 10.192.224.224\nexpect<\/span> \"password:\"<\/span>\nsend \"mypasswordn\"<\/span>\nexpect<\/span> \"*$\"<\/span>\nsend \"mkdir tmpdirn\"<\/span>\nexpect<\/span> \"*$\"<\/span>\n<\/code><\/pre>\n<\/p>\ntimeout\u6307expect\u7b49\u5f85\u547d\u4ee4\u81f3\u591a\u7b4930seconds<\/p>\n
\u8fd9\u4e2a\u4e8b\u4f8b\u5b9e\u9645\u4e0a\u662f\u901a\u8fc7ssh\u53bb\u767b\u9646\u8fdc\u7a0b\u673a\u5668\uff0c\u4f46\u662f\u5728\u8fdc\u7a0b\u673a\u5668\u4e0a\u521b\u4f73\u4e00\u4e2a\u76ee\u5f55\uff0c\u6211\u4eec\u770b\u89c1\u5728\u6211\u4eec\u8f93\u5165\u5bc6\u7801\u540e\u5e76\u6ca1\u6709\u53bbexpecteof\uff0c\u8fd9\u662f\u7531\u4e8essh\u8fd9\u4e2aspawn\u5e76\u6ca1\u6709\u7ed3\u675f\uff0c\u5e76\u4e14\u81ea\u52a8\u64cd\u4f5c\u65f6ssh\u5b9e\u9645\u4e0a\u4e5f\u4e0d\u4f1a\u81ea\u5df1\u7ed3\u675f\u9664\u975e\u4f60exit\uff1b\u6240\u4ee5\u4f60\u53ea\u80fdexpectbash\u7684\u63d0\u793a\u7b26\u5982\u4f55\u5b89\u88c5LINUX\uff0c\u5176\u5b9e\u4e5f\u53ef\u4ee5\u662f\u673a\u5668\u540d\u7b49linux set\u547d\u4ee4\u4f8b\u5b50<\/strong>\uff0c\u8fd9\u6837\u624d\u53ef\u4ee5\u5728\u8fdc\u7a0b\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\u3002<\/p>\n\u6ce8\u610f\uff0c\u8bf7\u4e0d\u8981\u7528spawnmkdirtmpdir\uff0c\u8fd9\u6837\u4f1a\u4fc3\u4f7f\u4e0a\u4e00\u4e2aspawn\u5373ssh\u7ed3\u675f\uff0c\u8fd9\u4e48\u4f60\u7684tmpdir\u5c06\u5728\u672c\u673a\u6784\u5efa\u3002<\/p>\n
\u5176\u5b9e\u5b9e\u9645\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u8981\u4f60\u786e\u8ba4sshkey\uff0c\u53ef\u4ee5\u901a\u8fc7\u5e76\u884c\u7684expect\u8fdb\u884c\u5904\u7406\uff0c\u4e0d\u591a\u8d58\u8a00\u3002<\/p>\n
#4<\/p>\n
\u6700\u540e\u4e00\u4e2ademo\u662f\u81ea\u5df1\u5c1d\u8bd5\u5199\u7684\uff0c\u529f\u80fd\u662f\u5b89\u88c5python3.6\uff0e\u6bd4\u8f83\u7b80\u5355\u7c97\u9c81\uff0c\u5c31\u662f\u7528spawn\u6765\u5f00\u542f\u4e0d\u540c\u7684\u8fdb\u7a0b\uff0c\u5e76\u59cb\u7ec8\u4fdd\u6301\u4ea4\u4e92\u72b6\u6001\uff0e\u8fd9\u6837\u505a\u7684\u7f18\u7531\u662f\u4e4b\u524d\u6269\u5199\u7684\u65f6\u4faf\uff0c\u4f7f\u7528send\u6765\u6267\u884c\u6307\u4ee4\u603b\u662f\u6709\u4e00\u4e9b\u95ee\u9898\uff0e\u540e\u6765\u53d1\u89c9\u8fd9\u6837\u5199\u51fa\u6765\u4e5f\u80fdwork\uff0e\u6682\u65f6\u4e0d\u6653\u5f97\u5f02\u540c\u70b9\uff0c\u5148\u8d34\u4e0a\u6765\u8bf7\u8bf8\u4f4d\u6307\u6559\uff0e<\/p>\n
\n
#!\/usr\/bin\/expect<\/span>\nset<\/span> timeout<\/span> 30\nspawn apt-get<\/span> install<\/span> -y software-properties-common\ninteract\nspawn add-apt-repository ppa:deadsnakes\nexpect<\/span> \"ENTER\"<\/span>\nsend \"n\"<\/span>\ninteract\nspawn apt-get<\/span> update\ninteract\nspawn apt-get<\/span> install<\/span> python3.6 -y\ninteract\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"expect\u662f\u5efa\u7acb\u5728tcl\u57fa\u7840\u4e0a\u7684\u4e00\u4e2a\u5de5\u5177\uff0c\u5b83\u7528\u6765\u8ba9\u4e00\u4e9b\u9700\u8981\u4ea4\u4e92\u7684\u4efb\u52a1\u81ea\u52a8\u5316\u5730\u5b8c\u6210\u3002\u8fd9\u91cc\u5c31\u662f\u6267\u884c\u4ea4\u4e92\u52a8\u4f5c\uff0c\u4e0e\u624b\u5de5\u8f93\u5165\u5bc6\u7801\u7684\u52a8\u4f5c\u7b49\u6548\u3002<\/p>\n","protected":false},"author":1,"featured_media":294805,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[4706,4710,4708,4709,4707],"class_list":["post-294804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-expect","tag-exp_continue","tag-send","tag-send_user","tag-spawn"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/294804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=294804"}],"version-history":[{"count":0,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/294804\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/294805"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=294804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=294804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=294804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}