如何用Python连接Linux系统并获取CPU温度?

2026-06-10 19:451阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计271个文字,预计阅读时间需要2分钟。

如何用Python连接Linux系统并获取CPU温度?

原创新品,引领潮流,品质生活,轻松拥有。

# -*- coding: utf-8 -*-
# @Time : 2022/3/31 9:05
# @Author : wangyafeng
# @FileName: ToLinux.py
# @Email :
# @Software: PyCharm

import paramiko,time,datetime


# 创建SSHClient实例对象
ssh = paramiko.SSHClient()

# 调用方法,标识没有远程机器的公钥,允许访问
# key = paramiko.RSAKey.from_private_key_file('/home/jeff/.ssh/id_rsa')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 连接远程机器 地址端口用户名密码
ssh.connect("192.168.2.203", 22, "root", "root")
#查看内存
while True:
# print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
# stdin, stdout, stderr = ssh.exec_command("free -g")
# out = str(stdout.read(), encoding='utf-8')
# print("===================内存=================================")
# print("total", out[97:99])
# print("buff/cache",out[146:148])
# print("available",out[158:160])
#同理 sensors同样 查看温度
print("=====温度======",datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sensorsstdin, sensorsstdout, sensorsstderr = ssh.exec_command("sensors")
sensorsout=str(sensorsstdout.read(), encoding='utf-8')
print(sensorsout)
time.sleep(2)



'''
1、连接linux
2、执行命令
3、解析
4、写入excle
5、加个while True:
'''

  


如何用Python连接Linux系统并获取CPU温度?

本文共计271个文字,预计阅读时间需要2分钟。

如何用Python连接Linux系统并获取CPU温度?

原创新品,引领潮流,品质生活,轻松拥有。

# -*- coding: utf-8 -*-
# @Time : 2022/3/31 9:05
# @Author : wangyafeng
# @FileName: ToLinux.py
# @Email :
# @Software: PyCharm

import paramiko,time,datetime


# 创建SSHClient实例对象
ssh = paramiko.SSHClient()

# 调用方法,标识没有远程机器的公钥,允许访问
# key = paramiko.RSAKey.from_private_key_file('/home/jeff/.ssh/id_rsa')
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 连接远程机器 地址端口用户名密码
ssh.connect("192.168.2.203", 22, "root", "root")
#查看内存
while True:
# print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
# stdin, stdout, stderr = ssh.exec_command("free -g")
# out = str(stdout.read(), encoding='utf-8')
# print("===================内存=================================")
# print("total", out[97:99])
# print("buff/cache",out[146:148])
# print("available",out[158:160])
#同理 sensors同样 查看温度
print("=====温度======",datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
sensorsstdin, sensorsstdout, sensorsstderr = ssh.exec_command("sensors")
sensorsout=str(sensorsstdout.read(), encoding='utf-8')
print(sensorsout)
time.sleep(2)



'''
1、连接linux
2、执行命令
3、解析
4、写入excle
5、加个while True:
'''

  


如何用Python连接Linux系统并获取CPU温度?