码迷,mamicode.com
首页 > 编程语言 > 详细

Python实现批量执行华为交换机脚本

时间:2019-08-24 20:19:51      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:host   send   bsp   invoke   div   style   name   for   save   

 1 #!/usr/bin/python3
 2 # -*- coding:utf-8 -*-
 3 import paramiko
 4 import time
 5 
 6 ssh = paramiko.SSHClient()
 7 key = paramiko.AutoAddPolicy()
 8 ssh.set_missing_host_key_policy(key)
 9 
10 
11 def execute(addr):
12 
13     ssh.connect(addr, 22, ‘test‘, ‘123456‘, timeout=200)
14     ssh_shell = ssh.invoke_shell()
15 
16     for script in scripts:
17         ssh_shell.send(script)
18         time.sleep(0.1)
19 
20 
21 if __name__ == ‘__main__‘:
22 
23     # 要批量执行脚本的设备
24     devices = [‘10.1.3.161‘, ‘10.1.3.162‘, ‘10.1.3.163‘]
25 
26     # 要批量执行的脚本
27     scripts = [‘sys\n‘, ‘sys sw\n‘, ‘q\n‘, ‘save\n‘, ‘Y\n‘]
28 
29     for device in devices:
30         execute(device)

 

Python实现批量执行华为交换机脚本

标签:host   send   bsp   invoke   div   style   name   for   save   

原文地址:https://www.cnblogs.com/heqiuyong/p/11405725.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!