| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import os
- import sys
- import paramiko
- from dotenv import load_dotenv
- sys.stdout.reconfigure(encoding='utf-8')
- sys.stderr.reconfigure(encoding='utf-8')
- repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- load_dotenv(dotenv_path=os.path.join(repo_root, ".env"))
- host = os.environ.get('SERVER_HOST')
- user = os.environ.get('SERVER_USER')
- password = os.environ.get('SERVER_PASS')
- if password == "your_db_password_here" or not password:
- password = None
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- try:
- ssh.connect(host, username=user, password=password, timeout=10)
- print("SSH Connected!")
-
- # Git log on the server
- stdin, stdout, stderr = ssh.exec_command("cd food_project && git log -n 5 --oneline")
- print("Git Log on Server:\n", stdout.read().decode('utf-8'))
-
- # Git status on the server
- stdin, stdout, stderr = ssh.exec_command("cd food_project && git status")
- print("Git Status on Server:\n", stdout.read().decode('utf-8'))
-
- # Git diff on the server
- stdin, stdout, stderr = ssh.exec_command("cd food_project && git diff app.py")
- print("Git Diff app.py on Server:\n", stdout.read().decode('utf-8'))
-
- except Exception as e:
- print(f"Error: {e}")
- finally:
- ssh.close()
|