expect批量备份交换机配置、MAC、DHCP SNOOPING、ARP、批量执行命令(四)

expect批量备份mac地址脚本


[root@test-syslog-o mac]#mkdir -p /var/script/mac/log/


1. [root@test-syslog-o mac]# viscript.exp


#! /usr/bin/expect

set ip [lindex $argv 0]

set timeout 1

spawn ssh -v -1 -c des -q -oStrictHostKeyChecking=no [email protected]@$ip


expect "*password:"


send "123456.Aa\r"


expect "*>"


send "dis mac-add | ex Eth-Trunk \r"


log_file $ip.log


while (1) {

sleep1

expect {

" ---- More ----" { send" " }

"Total*" { break }

}

}


expect ">"

send "quit\n"

expect eof


2. [root@test-syslog-o mac]# vi loop.sh


#!/bin/sh

while read ip

do

expect script.exp $ip


done < ip.txt


3. [root@test-syslog-o mac]#tar.sh


#!/bin/sh

/bin/sh loop.sh

tar -zcvf ./log/$(date +%Y%m%d%H%M)mac.tar.gz *.log

rm -rf /var/script/mac/*.log

/bin/cp -rf /var/script/mac/log/$(date+%Y%m%d%H%M)mac.tar.gz /mnt/share/Switch/BJ/mac


4.[root@test-syslog-o mac]# vi ip.txt

172.16.100.1

172.16.100.2

……

172.16.100.200


执行脚本[root@test-syslog-o mac]#sh -x tar.sh

你可能感兴趣的:(批量执行,华为,批量备份,expect脚本)