#!/usr/bin/env python3
"""SSH helper to run commands on the server"""
import subprocess
import sys

host = "204.197.172.20"
user = "id_tmitstoretop"
password = "tmitstore02#@!"

# Commands to run
commands = sys.argv[1] if len(sys.argv) > 1 else "pwd"

try:
    import paramiko
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(host, port=22, username=user, password=password, timeout=15)
    stdin, stdout, stderr = client.exec_command(commands)
    out = stdout.read().decode()
    err = stderr.read().decode()
    print("OUT:", out)
    if err:
        print("ERR:", err)
    client.close()
except ImportError:
    print("paramiko not installed, trying pip install...")
    subprocess.run([sys.executable, "-m", "pip", "install", "paramiko"], capture_output=True)
    print("Please run again after install")
except Exception as e:
    print(f"Error: {e}")
