#!/usr/bin/expect
#設定變量
set passwd "xxx;123"
puts {you want to deploy war , please enter the pool name:}
#從鍵盤擷取輸入内容
flush stdout
set pool_name [gets stdin]
puts "you want to deploy $pool_name"
set host "127.0.0.1"
set run_script "/depot/deploy.sh"
#switch判斷語句
switch $pool_name {
xxx {
set host 10.10.10.10
}
default {
puts "pool name is wrong! exit!"
exit 1
}
}
puts "you want to deploy war to $host"
#開啟新程序登陸伺服器
spawn ssh [email protected]$host
#expect期望程序輸入内容,send 自動輸入内容
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
send "/bin/sh $run_script\r"
#人機互動,停留在程序中,等待使用者做其它的操作
interact