#!/usr/bin/python3
# -*- coding:utf-8 -*-
import paramiko
import time
def main(host, username, password, commands):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=username, password=password,
port=22, allow_agent=False, look_for_keys=False)
channel = client.invoke_shell() # 请求交互式Shell会话
for command in commands:
channel.send(command + "\n") # 发送指令
while not channel.recv_ready(): # 等待数据到达
time.sleep(1)
output = channel.recv(40960)
print(output.decode())
client.close()
if __name__ == '__main__':
host = '192.168.33.129'
username = 'lyun'
password = '8'
commands = ["top -d 1 -b | grep 'edac-poller'"]
main(host, username, password, commands)
在linux系统操作可以输出执行结果
代码执行没有
有的服务可以输出执行结果