# -*- coding: utf-8 -*- """Merge nomdfs yt_long orphan into live card; verify neko unit env.""" from __future__ import annotations import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") PASS = "4669805" REMOTE = r''' import sqlite3, json, subprocess con=sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db") keep="94fce394-86b2-49ac-a841-f04d3c703067" orphan="cf0c1355-7586-418c-927a-df4762de5774" n=con.execute("UPDATE yt_long_jobs SET channel_pk=? WHERE channel_pk=?", (keep, orphan)).rowcount con.execute("DELETE FROM yt_long_channels WHERE id=?", (orphan,)) con.commit() print("migrated_jobs", n) print("remaining", [dict(r) for r in con.execute( "SELECT id,name,enabled,source_shorts_channel_pk FROM yt_long_channels WHERE name LIKE '%nomdfs%'")]) print("jobs_on_keep", [dict(r) for r in con.execute( "SELECT status, COUNT(*) n FROM yt_long_jobs WHERE channel_pk=? GROUP BY status", (keep,))]) # unit env out=subprocess.check_output(["systemctl","show","douyinweb-api","-p","Environment","--value"], text=True, errors="replace") for part in out.split(): if part.startswith("DY_NEKO_"): print("env", part) print("DONE") ''' def main(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(8): try: c.connect( "107.173.30.245", 4014, "eric", PASS, timeout=60, banner_timeout=120, allow_agent=False, look_for_keys=False, ) break except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2 + i) else: raise SystemExit("ssh failed") sftp = c.open_sftp() with sftp.file("/tmp/_merge_nomdfs.py", "w") as f: f.write(REMOTE) sftp.close() _, o, e = c.exec_command( f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_merge_nomdfs.py", timeout=60, ) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) c.close() if __name__ == "__main__": main()