import paramiko
import time

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("Triggering scan of last 40 unread emails (Low Priority)...")
        # Run scan.php once with limit 40
        cmd = "nice -n 19 ionice -c 3 php /var/www/html/repondeur_mail_grok/scripts/scan.php 40"
        stdin, stdout, stderr = ssh.exec_command(cmd)
        
        # We wait for completion to show results to user
        print(stdout.read().decode())
        err = stderr.read().decode()
        if err:
            print(f"Notes/Errors: {err}")
            
        ssh.close()
        print("Scan completed.")
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()
