#!/usr/bin/expect-f
if {$ARGC! = 3} {
Send_user "Usage: $argv 0 <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 is the role of telling expect to crawl"--more--"when the first"--"there is no space before, otherwise it will prompt bad flag
"*#" {break}
}
}
Send "exit\r"
Interact
This article from "Lifelong Learning" blog, reproduced please contact the author!
Automatic backup of qiming firewall configuration using expect batch