ex

#!/usr/bin/env expect

## Edit by wangsuipeng
## 20170223
## 远程执行脚本
## 请执行bash changeid 

set PASSWD XXXXXXX
set IP [lindex $argv 0]
set timeout 5

spawn ssh opmm@$IP
expect {
    "*(yes/no)?" {send "yes\r";exp_continue}
    "*password:" {send "$PASSWD\r";exp_continue}
    "*Password:" {send "$PASSWD\r"}
}
send "sudo su - root -c 'bash /home/ldaphome/wangsuipeng/changeid.sh'\r"  ##执行远程脚本/home/ldaphome/wangsuipeng/changeid.sh,此处省略脚本上传到远程主机的操作
##send "sudo su - root -c '>/etc/salt/minion_id && /etc/init.d/salt-minion restart'"  ##与上一步目的一样
expect eof