25 lines
1023 B
Python
25 lines
1023 B
Python
"""检查 .env 里的 POSTGRES_USER"""
|
|
import os, paramiko
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("207.57.129.228", port=19717, username="root",
|
|
password=os.environ["REMOTE_PASS"],
|
|
timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
# 看 .env
|
|
si, so, se = c.exec_command("bash -lc 'cd /srv/news && grep -E \"^POSTGRES_(USER|DB|PASSWORD)=\" .env'", timeout=10)
|
|
print("=== .env ===")
|
|
print(so.read().decode(errors="replace"))
|
|
|
|
# 直接 set 然后 echo
|
|
si, so, se = c.exec_command("bash -lc 'cd /srv/news && set -a && . ./.env && set +a && echo \"USER=$POSTGRES_USER DB=$POSTGRES_DB\"'", timeout=10)
|
|
print("=== set -a 之后 ===")
|
|
print(so.read().decode(errors="replace"))
|
|
|
|
# 最简方式: 传 PGPASSWORD
|
|
si, so, se = c.exec_command("bash -lc 'cd /srv/news && docker compose exec -T -e PGPASSWORD=news postgres psql -U news -d news -f /tmp/diag.sql'", timeout=15)
|
|
print("=== 硬编码 USER/DB ===")
|
|
print(so.read().decode(errors="replace"))
|
|
|
|
c.close()
|