#!/usr/bin/env python3 import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) cmd = r""" du -xh / --max-depth=1 2>/dev/null | sort -h | tail -20 echo --- du -xh /var --max-depth=2 2>/dev/null | sort -h | tail -20 echo --- du -xh /opt/douyinWEB/backend --max-depth=2 2>/dev/null | sort -h | tail -20 echo --- # live api status via cookie login python3 - <<'PY' import json, urllib.request, http.cookiejar cj=http.cookiejar.CookieJar() opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) req=urllib.request.Request('http://127.0.0.1:8014/api/auth/login', data=json.dumps({'username':'hackrobot','password':'Xiao4669805@'}).encode(), headers={'Content-Type':'application/json'}, method='POST') try: r=opener.open(req, timeout=20) print('login', r.status, r.read()[:200]) except Exception as e: print('login_fail', e) # try alternate req=urllib.request.Request('http://127.0.0.1:8014/api/login', data=json.dumps({'username':'hackrobot','password':'Xiao4669805@'}).encode(), headers={'Content-Type':'application/json'}, method='POST') try: r=opener.open(req, timeout=20) print('login2', r.status, r.read()[:300]) except Exception as e2: print('login2_fail', e2) for path in ['/api/yt-long/status','/api/yt-long/status?light=1']: try: r=opener.open('http://127.0.0.1:8014'+path, timeout=20) print(path, r.read().decode()[:2000]) except Exception as e: print(path, e) PY """ _i, o, e = c.exec_command(cmd, timeout=120) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err.strip(): print("[stderr]", err[:1500]) c.close()