# -*- coding: utf-8 -*- from __future__ import annotations import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE = r""" import sqlite3, json p='/opt/douyinWEB/backend/data/monitor.db' con=sqlite3.connect(p); con.row_factory=sqlite3.Row yt='UCk6CoQG0q9grwIr5UgxiXEQ' print('=== shorts by yt id ===') for r in con.execute('SELECT id,name,youtube_channel_id,oauth_profile_id,enabled,daily_max,oauth_ok,created_at FROM shorts_channels WHERE youtube_channel_id=? OR name LIKE ?', (yt,'%nomdfs%')): print(dict(r)) print('=== all shorts names+ids ===') for r in con.execute('SELECT id,name,youtube_channel_id,oauth_profile_id,enabled,oauth_ok FROM shorts_channels ORDER BY name'): print(dict(r)) print('=== yt_long same ===') try: for r in con.execute('SELECT id,name,youtube_channel_id,oauth_profile_id,enabled,source_shorts_channel_pk FROM yt_long_channels WHERE youtube_channel_id=? OR name LIKE ? OR source_shorts_channel_pk=?', (yt,'%nomdfs%','83fa0ed5-8020-4cb8-91e6-3620031547ba')): print(dict(r)) except Exception as e: print('yt_long err', e) print('=== assign groups ===') try: for r in con.execute("SELECT id,name,channel_pk,youtube_channel_id FROM yt_assign_groups WHERE name LIKE ? OR youtube_channel_id=? OR channel_pk=?", ('%nomdfs%', yt, '83fa0ed5-8020-4cb8-91e6-3620031547ba')): print(dict(r)) except Exception as e: print('assign err', e) con.close() """ c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=45, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() with sftp.file("/tmp/_dup2.py", "w") as f: f.write(REMOTE) sftp.close() _, o, e = c.exec_command("echo '4669805' | sudo -S -p '' python3 /tmp/_dup2.py", timeout=60) print((o.read() + e.read()).decode("utf-8", "replace")) c.close()