xepect 批量分發執行腳本

[root@localhost ~]# cat auto_expect.sh

#!/bin/bash

#Date:   2013-09-10

#Author: bourneye

#Pupose: autorun remote script


#remote host ips

ips=(192.168.10.134 192.168.10.135)

#local host pub_key

pub_key=`cat /root/.ssh/id_rsa.pub`


for ip in ${ips[*]}

do

com="ssh root@$ip"

expect -c "

           spawn $com;

           expect {

                  \"yes/no\" {send \"yes\r\";exp_continue}

                  \"password:\" {send \"123456\r\";exp_continue}

                  }

          expect "]*"

                   send \"echo $pub_key > /root/.ssh/authorized_keys\r\"

                   send \"wget ftp://192.168.10.128/*\r\"

                   send \"chmod 755 *.sh\r\"

                   send \"echo 'nohup sh init.sh;sh install_mysqld.sh &'|at now +1 min\r\"

                   expect eof

       "

done

#簡單理解:expect=if,send=do,但不可等同。

##注意,expect eof會退出連接狀態,中斷執行中的腳本;設置1分鐘後(視具體情況加減)執行。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章