Pythonのサーバー操作

クライアントの方法を介してサーバーにアクセスするためのpython

paramiko模块提供了连接服务的客户端,代码如下:
import paramiko
import time

# 操作Linux服务器
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.12.1.212',22,'root','openailab')
x_line = 0
# stdout 为正确输出,stderr为错误输出
stdin, stdout, stder = ssh.exec_command('free -h')
f0 = stdout.read().decode()
with open('./1.txt', 'w+') as f:
    f.write(f0)
    f.close()
data = []
with open('./1.txt', 'r') as f:
    for line in f:
        data.append(line)
    f.close()
list_top = data[0].split()
list_data = data[1].split()
print(list_top)
print(list_data)
time.sleep(1)

ここに画像を挿入説明

公開された25元の記事 ウォンの賞賛0 ビュー2683

おすすめ

転載: blog.csdn.net/weixin_43431593/article/details/103878308