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