# -*- coding: utf-8 -*- """SSH 连接自检:仅执行只读命令,不改动服务器""" import paramiko, sys HOST, PORT, USER, PWD = "8.137.181.63", 22, "root", "liyanxia@6688" cmds = [ ("站点目录", "ls /www/wwwroot/fenleixinxi.gzyakj.com.cn | head -30"), ("MySQL版本", "mysql -V"), ("PHP版本", "php -v 2>/dev/null | head -1"), ("远程.env", "cat /www/wwwroot/fenleixinxi.gzyakj.com.cn/.env 2>/dev/null"), ("磁盘空间", "df -h /www | tail -1"), ] cli = paramiko.SSHClient() cli.set_missing_host_key_policy(paramiko.AutoAddPolicy()) cli.connect(HOST, PORT, USER, PWD, timeout=20) for title, cmd in cmds: _, out, err = cli.exec_command(cmd, timeout=30) o, e = out.read().decode("utf-8", "ignore").strip(), err.read().decode("utf-8", "ignore").strip() print(f"===== {title} =====\n{o or e}\n") cli.close()