请帮忙,在 Paramiko 上执行脚本时出现问题,显示来自 switch.Aruba 2530 的信息时,OS 配置
脚本:
import paramiko
import getpass
import time
import json
with open('devices.json', 'r') as f:
devices = json.load(f)
with open ('commands.txt', 'r') as f:
commands = [line for line in f.readlines()]
username = input('Username: ')
password = getpass.getpass('Password: ')
max_buffer = 65535
def clear_buffer(connection):
if connection.recv_ready():
return connection.recv(max_buffer)
# Starts the loop for devices
for device in devices.keys():
outputFileName = device + '_output.txt'
connection = paramiko.SSHClient()
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
connection.connect(devices[device]['ip'], username=username, password=password, look_for_keys=False, allow_agent=False)
new_connection = connection.invoke_shell()
output = clear_buffer(new_connection)
time.sleep(3)
#new_connection.send("terminal length 5\n")
output = clear_buffer(new_connection)
with open(outputFileName, 'wb') as f:
for command in commands:
new_connection.send(command)
time.sleep(2)
output = new_connection.recv(max_buffer)
print(output)
f.write(output)
print ("\r\nEXIT"*15)
new_connection.close()
执行后产生以下内容: 无法理解的事情
在 output.txt 我有:
在 Comware 中一切正常。我基本了解 python,但我不明白这意味着什么。