import paramiko, base64 c=paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(hostname="139.159.253.131", username="root", password="bofang666.", timeout=25) sql = """SELECT id, name, lower_name, is_admin, is_active FROM "user" WHERE lower_name IN ('fmode','xadmin') ORDER BY id;""" b64 = base64.b64encode(sql.encode()).decode() cmd = f'echo {b64} | base64 -d > /tmp/q.sql && PGPASSWORD=666 psql -h 127.0.0.1 -p 5433 -U dev -d gogs -At -f /tmp/q.sql; rm -f /tmp/q.sql' _,o,e = c.exec_command(cmd, timeout=45) print(o.read().decode()[:800]); print("ERR", e.read().decode()[:200]) # 找 hardware 相关仓库 sql2 = "SELECT id, lower_name, is_private FROM repository WHERE lower_name ILIKE '%hardware%' OR lower_name ILIKE '%xianti%' OR lower_name ILIKE '%壳%' LIMIT 10;" b2 = base64.b64encode(sql2.encode()).decode() cmd2 = f'echo {b2} | base64 -d > /tmp/q2.sql && PGPASSWORD=666 psql -h 127.0.0.1 -p 5433 -U dev -d gogs -At -f /tmp/q2.sql; rm -f /tmp/q2.sql' _,o,e = c.exec_command(cmd2, timeout=45) print("=== 现有 hardware 仓 ==="); print(o.read().decode()[:500]) c.close()