该脚本实现自动化无需人机交互登陆远程多个ip(密码都一样)执行命令重启vspc服务。
1.创建ip_list_path
2. sh restartVspc.sh <密码>
#!/bin/bash
set -eux
set timeout 30
password=$1
vspc_ip_list_path='./../../home/houbo/vspc_ip.list_test'
for i in $(cat $vspc_ip_list_path)
do
/usr/bin/expect << EOF
# open a new process
spawn /usr/bin/ssh root@$i
# accept strings from process
expect {
#"(yes/no)?"
#{
# send "yes
"
# expect "*assword:" { send "$password
"}
#}
"*assword:"
{
# send strings to the process
send "$password
"
}
}
expect "*]#"
send "/usr/bin/supervisorctl restart vSPCServer
"
expect "*]#"
send "exit
"
expect eof
EOF
done