Python实现批量执行华为交换机脚本
#!/usr/bin/python3
# -*- coding:utf-8 -*-
import paramiko
import time
ssh = paramiko.SSHClient()
key = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(key)
def execute(addr):
ssh.connect(addr, 22, 'test', '123456', timeout=200)
ssh_shell = ssh.invoke_shell()
for script in scripts:
ssh_shell.send(script)
time.sleep(0.1)
if __name__ == '__main__':
# 要批量执行脚本的设备
devices = ['10.1.3.161', '10.1.3.162', '10.1.3.163']
# 要批量执行的脚本
scripts = ['sys\n', 'sys sw\n', 'q\n', 'save\n', 'Y\n']
for device in devices:
execute(device)
请自行测试,如有问题请联系 www.oocolo.com