How to use expect script to realize backup Huawei Switch configuration (iii)

Source: Internet
Author: User
Tags backup

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.