sh2/d2ypp2/tools/compare_hosts2.py
2026-06-14 10:41:48 -05:00

34 lines
1.4 KiB
Python

#!/usr/bin/env python3
import paramiko
HOSTS = [("10.88.0.4", "eric", "4669805"), ("10.88.0.5", "eric", "4669805")]
def run(host, user, pw, cmd, timeout=40):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, username=user, password=pw, timeout=15)
try:
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
return (o.read() + e.read()).decode('utf-8', 'replace')
finally:
c.close()
cmds = [
"lscpu | grep 'Model name'",
"ps aux | grep youtube.py | grep -v grep",
"ls -la /home/eric/d2ypp2/youtube.py /home/eric/d2ypp2-src/youtube.py 2>&1",
"grep -r LIVE_PM2 /home/eric/d2ypp2-src/.pm2/logs/*.log 2>/dev/null | tail -1; ls /home/eric/d2ypp2/.pm2/logs/youtube2__ch_*-out.log 2>/dev/null | head -3",
"cd /home/eric/d2ypp2 2>/dev/null || cd /home/eric/d2ypp2-src; pwd; .venv/bin/python -c \"import asyncio; from src.spider import get_douyin_app_stream_data; print('test')\" 2>&1 | head -3",
"curl -sS -m 8 'http://127.0.0.1:8001/restart?process=youtube2__ch_mpwri36r_z5lm2' 2>/dev/null | head -c 300",
"sleep 3; ps aux | grep youtube.py | grep -v grep | head -3",
]
for host, user, pw in HOSTS:
print('\n' + '='*20, host, '='*20)
for cmd in cmds:
print('\n--', cmd[:65])
try:
print(run(host, user, pw, cmd).encode('ascii','backslashreplace').decode()[:3500])
except Exception as ex:
print('ERR', ex)