print_remote_logs.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import sys
  3. import paramiko
  4. from dotenv import load_dotenv
  5. sys.stdout.reconfigure(encoding='utf-8')
  6. sys.stderr.reconfigure(encoding='utf-8')
  7. repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. load_dotenv(dotenv_path=os.path.join(repo_root, ".env"))
  9. host = os.environ.get('SERVER_HOST')
  10. user = os.environ.get('SERVER_USER')
  11. password = os.environ.get('SERVER_PASS')
  12. if password == "your_db_password_here" or not password:
  13. password = None
  14. ssh = paramiko.SSHClient()
  15. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  16. try:
  17. ssh.connect(host, username=user, password=password, timeout=10)
  18. print("SSH Connected!")
  19. # Run docker inspect directly on the container name
  20. print("--- Inspect ---")
  21. stdin, stdout, stderr = ssh.exec_command("docker inspect food_project-ingest-run-96423d806118")
  22. out = stdout.read().decode('utf-8', errors='ignore')
  23. err = stderr.read().decode('utf-8', errors='ignore')
  24. print("STDOUT:")
  25. print(out)
  26. print("STDERR:")
  27. print(err)
  28. except Exception as e:
  29. print(f"Error: {e}")
  30. finally:
  31. ssh.close()