我需要一个Python脚本,它将从PUTTY收集日志/信息,然后需要将这些信息存储在另一个保存在驱动器中的文件中。
答案 0 :(得分:0)
import subprocess
import sys
HOST="127.0.0.1"
# Ports are handled in ~/.ssh/config since we use OpenSSH
COMMAND="uname -a"
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],
shell=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
print result