Files
soul-yongping/soul-api/miner_guard_check.py

41 lines
1.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""检查 miner_guard 安装状态"""
import os, sys
try:
import paramiko
except ImportError:
print("pip install paramiko"); sys.exit(1)
def get_cfg():
try:
import importlib.util
spec = importlib.util.spec_from_file_location("m", os.path.join(os.path.dirname(__file__), "master.py"))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
c = mod.get_cfg()
return {"host": c["host"], "user": c.get("user","root"), "password": c.get("password",""), "port": 22022}
except: return {}
cfg = get_cfg()
if not cfg.get("host"): print("配置失败"); sys.exit(1)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(cfg["host"], port=cfg["port"], username=cfg["user"], password=cfg["password"], timeout=15)
def run(cmd, to=10):
i, o, e = c.exec_command(cmd, timeout=to)
return o.read().decode("utf-8","replace").strip()
print("=== crontab -l ===")
print(run("crontab -l 2>/dev/null"))
print("\n=== /root/miner_guard.sh 存在? ===")
print(run("ls -la /root/miner_guard.sh 2>/dev/null"))
print("\n=== 手动执行一次脚本 ===")
print(run("/bin/bash /root/miner_guard.sh 2>&1"))
print("\n=== 日志最后5行 ===")
print(run("tail -5 /var/log/miner_guard.log 2>/dev/null"))
c.close()