{"id":6947,"date":"2017-09-03T09:18:00","date_gmt":"2017-09-03T01:18:00","guid":{"rendered":"http:\/\/rmohan.com\/?p=6947"},"modified":"2017-09-03T09:18:00","modified_gmt":"2017-09-03T01:18:00","slug":"expectsshpasspash","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6947","title":{"rendered":"expect,sshpass,pash"},"content":{"rendered":"<p><strong>expect,sshpass,pash<\/strong><br \/>\nrpm -qa expect<\/p>\n<p>yum install expect -y<\/p>\n<p>useradd mohan<\/p>\n<p>echo 123456|passwd &#8211;stdin mohan<\/p>\n<p>su &#8211; mohan<\/p>\n<p>ssh-keygen -t dsa -P &#8221; -f ~\/.ssh\/id_dsa &gt;\/dev\/null 2&gt;&amp;1<\/p>\n<p>yum install lrzsz -y<\/p>\n<p>cat mohan_sshkey.exp<br \/>\n#!\/usr\/bin\/expect<br \/>\nif { $argc !=2 } {<br \/>\nsend_user &#8220;usage: expect mohan_sshkey.exp file host\\n&#8221;<br \/>\nexit<br \/>\n}<br \/>\n#define var<br \/>\nset file [lindex $argv 0]<br \/>\nset host [lindex $argv 1]<br \/>\nset password &#8220;123456&#8221;<br \/>\n#spawn scp \/etc\/hosts root@10.0.0.142:\/etc\/hosts<br \/>\n#spawn scp -P52113 $file testserver@$host:$dir<br \/>\nspawn ssh-copy-id -i $file &#8220;-p 22 oldgirl888@$host&#8221;<br \/>\nexpect {<br \/>\n&#8220;yes\/no&#8221; {send &#8220;yes\\r&#8221; ;exp_continue}<br \/>\n&#8220;password&#8221; {send &#8220;$password\\r&#8221;}<br \/>\n}<br \/>\nexpect cof<br \/>\nexit -onexit {<br \/>\nsend_user &#8220;testserver say good bye to you!\\n&#8221;<br \/>\n}<br \/>\n#script usage<br \/>\n#expect testserver-6.exp file host dir<br \/>\n#example<br \/>\n#expect mohan_sshkey.exp file host dir<br \/>\n#expect mohan_sshkey.exp ~\/etc\/hosts 10.0.0.41:~<\/p>\n<p>&nbsp;<\/p>\n<p>expect mohan_sshkey.exp .ssh\/id_dsa.pub 192.168.1.21<\/p>\n<p>&nbsp;<\/p>\n<p>#!\/bin\/sh<br \/>\n. \/etc\/init.d\/functions<br \/>\nfor ip in 8 31 41<br \/>\ndo<br \/>\nexpect mohan_sshkey.exp ~\/.ssh\/id_dsa.pub 192.168.1.$ip &gt;\/dev\/null 2&gt;&amp;1<br \/>\nif [ $? -eq 0 ];then<br \/>\naction &#8220;$ip&#8221; \/bin\/true<br \/>\nelse<br \/>\naction &#8220;$ip&#8221; \/bin\/false<br \/>\nfi<br \/>\ndone<\/p>\n","protected":false},"excerpt":{"rendered":"<p>expect,sshpass,pash rpm -qa expect<\/p>\n<p>yum install expect -y<\/p>\n<p>useradd mohan<\/p>\n<p>echo 123456|passwd &#8211;stdin mohan<\/p>\n<p>su &#8211; mohan<\/p>\n<p>ssh-keygen -t dsa -P &#8221; -f ~\/.ssh\/id_dsa &gt;\/dev\/null 2&gt;&amp;1<\/p>\n<p>yum install lrzsz -y<\/p>\n<p>cat mohan_sshkey.exp #!\/usr\/bin\/expect if { $argc !=2 } { send_user &#8220;usage: expect mohan_sshkey.exp file host\\n&#8221; exit } #define var set file [lindex $argv 0] set [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6947"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6947"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6947\/revisions"}],"predecessor-version":[{"id":6948,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6947\/revisions\/6948"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}