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

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

1、Python腳本shell

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)ssh

command = 'sh running-config \r 'ide

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

if not result:
result = stderr.read()class

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

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

backup.close()
ssh.close()command

相關文章
相關標籤/搜索