交换机批量配置脚本
交换机批量配置脚本Linux shell
1、安装一台Linux虚拟机 2、脚本使用shell运行 多台交换机需要配置相同的命令,增加循环语句后简化繁琐配置
将系列内容放在xxx.sh文件里面
Shell脚本:telnet
#!/bin/sh
USERNAME=huawei --- 交换机用户名
PASSWORD=huawei@huawei --- 交换机密码
for HOST_IP in 192.168.150.{1..3} --- 交换机管理IP
do
(
sleep 1
echo ${USERNAME}
sleep 1
echo ${PASSWORD}
sleep 1
echo "system" --- 输入交换机的命令
echo "int ran eth 0/0/1 to 0/0/24"
echo "port link-t a"
echo "port de v 1000"
echo "return"
echo "save"
echo "y"
echo -e "\n"
sleep 7 --- 间隔时间(S)
) | telnet ${HOST_IP}
done
使用下列脚本需先安装expect
Shell脚本:ssh
Linux下安装expect
[root@localhost ~]# yum install -y expect
编写脚本后缀名为 (.sh) 运行命令:expect test.sh 或者 ./test.sh
#!/usr/bin/expect -f
for {set i 16} {$i <= 20} {incr i} {
spawn ssh huawei@10.30.7.$i
set timeout 3
expect "password:"
set timeout 2
send "huawei@huawei\r"
set timeout 1
expect "$"
set timeout 3
send "n\r"
send "sys\r"
send "int eth0/0/24\r"
send "port link-t a\r"
send "port de vlan 100\r"
send "ret\r"
send "quit\r"
expect eop
}
exit
以上为示例,自己研究更多。
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
曹少卿的Blog!
喜欢就支持一下吧
打赏
微信
支付宝