- cat >ssh.exp <<\! #没有!之前的\,那么set的变量不被here doc产生的ssh.exp生效。原因未知
- #!/usr/bin/expect
set timeout 60
set pwd "123456"
spawn ssh 172.18.0.1
- expect {
- "not know" {send_user "[exec echo \"not know\"]";exit}
- "(yes/no)?" {send "yes\r";exp_continue}
- "password:" {send "$pwd\r"}
- "Permission denied, please try again." {
- send_user "[exec echo \"Error:Password is wrong\"]"
- exit }
expect eof
}
expect "*#"
send "/etc/init.d/keepalived stop\r"
- send "sh ./chg_keepalived.sh &\r"
send "\r"
send "exit\r"
expect eof
- !
ip,command,password可以在一个文件里,直接写:
然后while read x;do expect ssh.exp $i;done
假如要记录日志,直接在set下添加
log_file $ip.log
========= 注意expect eof ====================
阅读(3796) | 评论(0) | 转发(0) |