# -*- 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() # 调用方法,标识没有
# @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:
'''