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

相关文章
相关标签/搜索