Python 腳本登錄交換機實現自動配置備份

Python 腳本登錄交換機實現自動配置備份

一、Python腳本

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("10.x.x.x", 22,"用戶名","密碼",allow_agent=False,look_for_keys=False)

command = 'sh running-config \r '

stdin, stdout, stderr = ssh.exec_command(command)
#stdin, stdout, stderr = ssh.invoke_shell(command)
a=[]
result = stdout.readlines()

if not result:
result = stderr.read()

backup=open("/root/worke/beifen/beifen.txt","w")

for line in result:
print(line)
backup.write(line)

backup.close()
ssh.close()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章