ssh自动登录服务器并执行一条命令取得返回结果后退出
# 执行时候至少要给出一个IP和命令# 如果要在多台服务器上执行命令
# 则最后一个参数是要执行的命令
# 其它都是服务器IP
#
#!/usr/bin/expect
set user {YOUR_USER_NAME}
set password {YOUPASSWOD}
if {$argc < 2} {
puts "Usage: script IP IP2 ... COMMAND"
exit 1
}
set hosts
set command
foreach host $hosts {
spawn ssh $user@$host
expect \
"yes*\\?" {send "yes\r"; exp_continue} \
"password:"{send "$password\r"}
expect "*\\\$"
send "$command\r"
expect "*\\\$"
send "exit\r"
puts ""
}
页:
[1]