首页 > 代码库 > 使用expect批量自动备份启明防火墙配置
使用expect批量自动备份启明防火墙配置
#!/usr/bin/expect -f
if { $argc != 3 } {
send_user "用法: $argv0 <server> <login> <password>\n"
exit
}
set timeout 1
set TERM ANSI
set SERVER [lindex $argv 0]
set LOGIN [lindex $argv 1]
set PASSWD [lindex $argv 2]
spawn telnet
expect "telnet> "
send "open $SERVER\r"
sleep 10
expect "login:"
send "$LOGIN\r"
sleep 1
expect "Password:"
send "$PASSWD\r"
sleep 1
expect "*>"
send "en\r"
sleep 1
expect "*#"
log_file /var/log/conf/[clock format [clock seconds] -format "%Y-%m-%d"].$SERVER.log
send "show run\r"
while (1) {
sleep 1
expect {
-ex "--More-- " { send " " } #-ex的作用是告诉expect 在抓取“--More-- ”时第一个“--”前没有空格,否则会提示bad flag
"*#" { break }
}
}
send "exit\r"
interact
本文出自 “学无止境” 博客,转载请与作者联系!
使用expect批量自动备份启明防火墙配置