16 Star 44 Fork 45

现任明教教主-乾颐堂 / qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.02.17 paramiko ssh执行多个命令 932 Bytes
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-02-17 09:15 . new file
import paramiko
import time
import sys
def copyfinxos(verno, device):
ssh=paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.1.1.50',port=22,username='admin',password='cisco',compress=True)
if device == 'A':
cmd = ('connect nxos a\n').encode()
elif device == 'B':
cmd = ('connect nxos b\n').encode()
else:
print('device is error')
chan=ssh.invoke_shell()
time.sleep(1)
x = chan.recv(2048).decode()
chan.send(cmd)
time.sleep(1)
x = chan.recv(2048).decode()
chan.send(('show run' + r' | ' + 'no-more\n').encode())
time.sleep(5)
x = chan.recv(409600).decode()
configfiletmp = '/python/DCfile/' + verno + '/' + 'FI-' + device + '.txt'
configtmp = open(configfiletmp, 'w')
configtmp.write(x)
configtmp.close()
chan.close()
ssh.close()
if __name__ == '__main__':
copyfinxos('v2', 'A')
Python
1
https://gitee.com/qytang/qytang_Python.git
git@gitee.com:qytang/qytang_Python.git
qytang
qytang_Python
qytang_Python
master

搜索帮助