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

expect批量执行交换机命令脚本

1[root@test-syslog-o script]# vi script.exp

#!/usr/bin/expect


set ip [lindex $argv 0]

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

expect "*password:"

send "123456.Aa\r"

expect "*>"

send "sys\r"

expect "*]"

send "user-int consle 0\r"

send "set authentication password cipher1!2z\$9B\r" #这里的“\”代表转义

expect "*]"

send "quit\n"

send " port-group 1\r"

send " group-member Ethernet 0/0/1 toEthernet 0/0/46\r"

send " port link-type access\r"

send " port default vlan 10\r"

send " quit\n"

send " undo port-group 1\r"

send "quit\n"

send " sa\r"

send " \r"

send " y\r"

send " \r"

send "quit\n"

set timeout 10

expect eof

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

#!/bin/sh

while read ip

do

expect script.exp $ip


done < ip.txt


3.[root@test-syslog-o script]# vi ip.txt

172.16.100.1

172.16.100.2

……

172.16.100.254


执行脚本[root@test-syslog-oscript]#sh loop.sh

以上以华为S5700为范例,其他型号交换机需替换相应命令。


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