{"id":69,"date":"2010-05-22T20:15:07","date_gmt":"2010-05-23T00:15:07","guid":{"rendered":"http:\/\/www.xavignu.com\/?p=69"},"modified":"2010-05-22T20:15:07","modified_gmt":"2010-05-23T00:15:07","slug":"using-expect","status":"publish","type":"post","link":"https:\/\/www.xavignu.com\/?p=69","title":{"rendered":"Using expect"},"content":{"rendered":"<p>Let&#8217;s give a brief intro to <a href=\"http:\/\/expect.nist.gov\/\" target=\"_blank\">expect<\/a>. Basically is a tool for automating interactive applications such as FTP, telnet, ssh and similar. Expect has regular expression pattern matching and general program capabilities.<\/p>\n<p>Let&#8217;s start installing Expect. Type in your <a href=\"http:\/\/www.debian.org\" target=\"_blank\">Debian<\/a> based box:<\/p>\n<p><b>sudo aptitude install expect<\/b> <\/p>\n<p>That&#8217;s it. You are done.<\/p>\n<p>Now lets write a simple ssh expect script. Substitute user, password and hostname for the user, password and hostname to the machine you want to log into.<br \/>\n<br \/>\n<b>#!\/usr\/bin\/expect<br \/>\nspawn ssh user@hostname<br \/>\nexpect &#8220;user@hostname&#8217;s password:&#8221;<br \/>\nsend &#8220;password\\r&#8221;<br \/>\nexpect &#8220;$\\r&#8221;<br \/>\nsend &#8220;who; pwd; last | head\\r&#8221;<br \/>\nexpect &#8220;$\\r&#8221;<br \/>\nsend &#8220;date; exit\\r&#8221;<br \/>\nexpect eof<\/B><\/p>\n<p>The script is pretty simple. It basically logs into a box and executes date, pwd, who and last commands. But it clearly shows the power of expect for automating tasks.<\/p>\n<p>More info at <a href=\"http:\/\/en.wikipedia.org\/wiki\/Expect\" target=\"_blank\">Wikipedia<\/a> and <a href=\"http:\/\/expect.nist.gov\/\" target=\"_blank\">Expect homepage<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s give a brief intro to expect. Basically is a tool for automating interactive applications such as FTP, telnet, ssh and similar. Expect has regular expression pattern matching and general program capabilities. Let&#8217;s start installing Expect. Type in your Debian based box: sudo aptitude install expect That&#8217;s it. You are done. Now lets write a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[24,22,6,23,7,70],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/pTQgt-17","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/69"}],"collection":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":0,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xavignu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}