import paramiko import time import sys 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) def run(cmd, timeout=180): _, o, e = c.exec_command(cmd, timeout=timeout) return o.read().decode("utf-8", "replace"), e.read().decode("utf-8", "replace") print(run("cd /opt/douyinWEB && git pull origin dev 2>&1")[0]) c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1") time.sleep(8) print("api", run("systemctl is-active douyinweb-api")[0]) cmd = r'''cd /opt/douyinWEB/backend && .venv/bin/python <<'PY' from app import db, tiktok_db, tiktok_profile, tiktok_session db.init_db() for ch in tiktok_db.list_tiktok_channels(): if not tiktok_session.channel_has_session(ch): print("skip", ch.get("name")) continue try: r = tiktok_profile.fetch_profile_for_channel(ch["id"]) p = r.get("profile") or {} print( "ok", ch.get("name"), "@" + str(p.get("tiktok_username") or ""), "fans", p.get("follower_count"), "vids", p.get("video_count"), "heart", p.get("heart_count"), "avatar", bool(p.get("avatar_url")), str(p.get("avatar_url") or "")[:80], ) except Exception as e: print("fail", ch.get("name"), e) PY''' out, err = run(cmd) print(out) if err.strip(): print("STDERR", err[-2000:]) c.close()