{"id":4566,"date":"2021-07-29T15:24:51","date_gmt":"2021-07-29T06:24:51","guid":{"rendered":"\/blog\/?p=4566"},"modified":"2023-09-21T09:26:31","modified_gmt":"2023-09-21T00:26:31","slug":"expect-sudo-passwd-%ec%bb%a4%eb%a7%a8%eb%93%9c-%ec%b2%b4%ed%81%ac","status":"publish","type":"post","link":"https:\/\/hasu0707.duckdns.org\/blog\/?p=4566","title":{"rendered":"[expect] sudo passwd \ucee4\ub9e8\ub4dc \uccb4\ud06c"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/usr\/bin\/expect\n\nset serverIP [lindex $argv 0]\nset loginUser \"user0\"\nset loginPassword \"&lt;password>\"\nset log_file \"test.log\"\n\nset timeout 5\n\nset fileid [open $log_file \"a+\"]\n\n## ssh \ub85c\uadf8\uc778\nspawn ssh $loginUser@$serverIP\n\n## SSH \ud3ec\ud2b8 \uc5f0\uacb0\uc774 \ubd88\uac00\ud560 \uacbd\uc6b0 \uc811\uc18d \uc989\uc2dc \uc624\ub958 \ucc98\ub9ac\nexpect_after eof { puts $fileid \"FAILED-no_route $serverIP\"; close $fileid; puts \"\\n\"; exit 1 }\n\n## interact with SSH\nexpect \"yes\/no\" { send \"yes\\r\" }\n\n## \uc624\ub79c \uc2dc\uac04 \uc811\uc18d\uc774 \uc548\ub420 \uacbd\uc6b0 \uc811\uc18d \ubd88\uac00 \ucc98\ub9ac\nexpect \"assword:\" { send \"$loginPassword\\r\" } \\\n  timeout { puts $fileid \"FAILED-connect $serverIP\"; close $fileid; puts \"\\n\"; exit 2 }\n\n## Password \ud504\ub86c\ud504\ud2b8\uac00 \ub610 \ub098\uc624\uba74 \ud328\uc2a4\uc6cc\ub4dc \ubd88\uc77c\uce58 \ucc98\ub9ac\nexpect \"assword:\" { puts $fileid \"FAILED-login $serverIP\"; close $fileid; puts \"\\n\"; exit 3 }\n\n## $ \ud504\ub86c\ud504\ud2b8\ub97c \uae30\ub2e4\ub9ac\uace0 LANG \ubcc0\uc218 \uc14b\ud305\nexpect \"$\"\nsend \"export LANG=C\\r\"\n\n## $ \ud504\ub86c\ud504\ud2b8\ub97c \uae30\ub2e4\ub9ac\uace0 sudo \ucee4\ub9e8\ub4dc \uc2e4\ud589\nexpect \"$\"\nsend \"sudo passwd user1\\r\"\nexpect \"assword:\" { puts $fileid \"SUCCESS $serverIP\"; } \\\n  timeout { puts $fileid \"FAILED-sudo $serverIP\"; close $fileid; puts \"\\n\"; exit 4 }\nputs \"\\n\"\n\nclose $fileid\nclose $spawn_id\nexit 0<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[],"class_list":["post-4566","post","type-post","status-publish","format-standard","hentry","category-computing_tools"],"_links":{"self":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4566"}],"version-history":[{"count":0,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4566\/revisions"}],"wp:attachment":[{"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hasu0707.duckdns.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}