The previous two posts have explained how to back up the configuration file, the function of the expect script is to provide interaction, log in each switch to perform a backup command to copy it to the TFTP server. But in our normal work, the general backup method is to dis cu or sh run and then copy the information on the screen, in fact, the previous script can be slightly modified to use this method to back up the configuration, of course, this method can not only back up the configuration file, just replace the relevant commands, Backing up any information that is printed on the screen is OK. Let's take a backup MAC address as an example to illustrate.
1. Loginfo.exp
#! /usr/bin/expect
Set IP [lindex $argv 0]
Set timeout 1
Spawn ssh-v -1-c des-q-o stricthostkeychecking=no wang11@game-inc.com@ $ip
Expect "*password:"
Send "p@ssw0rd\r"
Expect "*>"
Send "Dis mac-add | Ex eth-trunk \ r "
Log_file $ip. Log #记录输出的信息到 $ip. log
while (1) {
Sleep 1
Expect {
"----more----" {send "} #若匹配"----more----", press the SPACEBAR continuously
"total*" {break} #匹配 "total*" returns out of loop
}
Expect ">"
Send "quit\n"
Expect EOF
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Network/jhjs/
2. loop.sh
#! /bin/sh
While read IP
Todo
./loginfo.exp $ip
Done < Ip.txt
3. tar.sh
#! /bin/sh
SH loop.sh
Tar JCVF $ (date +%y%m%d). tar.bz2 *.log
RM-RF *.log
This article from the "Wang 11" blog, please be sure to retain this source http://wangshiyi.blog.51cto.com/703685/1122375