前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过expect脚本在H3C设备批量执行命令 By HKL,

通过expect脚本在H3C设备批量执行命令 By HKL,

作者头像
hiplon
发布2020-07-22 10:59:10
8430
发布2020-07-22 10:59:10
举报
文章被收录于专栏:VNFVNF

1.本文主要记录了在Linux系统中使用自动化测试工具expect通过ssh登陆H3C设置并批量执行相同命令

2.安装expect

以ubuntu为例

代码语言:javascript
复制
sudo apt install expect

3.编辑expect脚本

以ssh登陆H3C设置并配置AAA的服务为例

expect.sh

代码语言:javascript
复制
#!/usr/bin/expect
set timeout 5
set f [open ip.txt]   #ip.txt为同目录下配置交换机ip地址的文件
while {1} {
	set ip [gets $f]
	if {[eof $f]} {
		close $f
		break
	}

	spawn ssh -c aes128-cbc -oStrictHostKeyChecking=no YourUsername@$ip
	#expect "Please type 'yes' or 'no'"
	#send "yes\r"
	expect "*password:"
	send "YourPassword\r" #password123为ssh的登陆密码
	expect "*>"
	send "sys\r"
	expect "*]"
	send "radius scheme Schema_aaa\r"
	expect "*a]"
	send "primary authentication YourRadiusPrimaryIP\r"
	expect "*a]"
	send "primary accounting YourRadiusPrimaryIP\r"
	expect "*a]"
	send "secondary authentication YourRadiusSecondaryIP\r"
	expect "*a]"
	send "secondary accounting YourRadiusSecondaryIP\r"
	expect "*a]"
	send "quit\r"
	expect "*]"
	send "quit\r"
	expect "*>"
	send "save\r"
	expect "*Y/N]"
	send "Y\r"
	expect "*):"
	send "\r"
	expect "*Y/N]"
	send "Y\r"
	expect "*>"
	send "quit\r"
}
interact

其中ip.txt以如下为例

代码语言:javascript
复制
10.1.1.1
10.1.1.2
10.1.1.3
10.1.1.4
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档