import paramiko

HOST = "135.125.102.180"
USER = "ubuntu"
PASS = "BotPascal2026!"

def main():
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username=USER, password=PASS)
        
        print("🔍 Checking PID from logs (latest pgrep outcome)...")
        # Re-run pgrep to see current state
        stdin, stdout, stderr = ssh.exec_command("pgrep -a -f scan_loop.php")
        pgrep_out = stdout.read().decode()
        print(f"Current PGREP:\n{pgrep_out}")
        
        if pgrep_out.strip():
            for line in pgrep_out.splitlines():
                pid = line.split()[0]
                print(f"\n🔍 Inspecting PID {pid}...")
                stdin, stdout, stderr = ssh.exec_command(f"ps -p {pid} -o user,pid,ppid,cmd,start,time")
                print(stdout.read().decode())
        
        ssh.close()
    except Exception as e:
        print(f"❌ Error: {e}")

if __name__ == "__main__":
    main()
