From e7cbed897775cacae02f8debe5e4564df0f0ceb9 Mon Sep 17 00:00:00 2001 From: Michel Date: Sun, 20 Apr 2025 09:31:12 +0200 Subject: [PATCH] =?UTF-8?q?"Am=C3=A9liorations=20notoires=20programmes"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Vider_logs_Vps.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Vider_logs_Vps.py b/Vider_logs_Vps.py index e69de29..2fcc143 100644 --- a/Vider_logs_Vps.py +++ b/Vider_logs_Vps.py @@ -0,0 +1,62 @@ +import paramiko + +# Configuration +hostname = "54.36.188.119" +port = 22 +username = "debian" +password = "9DpdTzFj" +chemin_script = "/home/debian/travail/tools/Vider_logs_Vps_local.py" + +# Connexion SSH avec clé + passphrase +try: + print("Connexion SSH en cours...") + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(hostname, port=port, username=username, password=password) + + # Exécution du script distant + print(f"Exécution du script : {chemin_script}") + stdin, stdout, stderr = ssh.exec_command(f"python3 {chemin_script}") + + print("\n--- Résultat ---") + for ligne in stdout: + print(ligne.strip()) + + erreurs = stderr.read().decode() + if erreurs: + print("\n--- Erreurs ---") + print(erreurs) + + ssh.close() + print("\n✅ Terminé avec succès.") +except Exception as e: + print(f"❌ Erreur : {e}") +# --- FIN DU CODE ACTIF --- + +# ============================================================================ +# 👇 CI-DESSOUS : VERSION DU SCRIPT À DÉPLOYER SUR LE VPS (à copier/coller) +# ============================================================================ + +""" +#!/usr/bin/env python3 +import os + +racine_logs = "/var/log" + +nb_vides = 0 +for dossier, _, fichiers in os.walk(racine_logs): + for fichier in fichiers: + if fichier.endswith(".log"): + try: + with open(os.path.join(dossier, fichier), "w") as f: + pass + nb_vides += 1 + except Exception: + pass + +print(f"{nb_vides} fichiers log vidés.") +""" + +# ============================================================================ +# FIN DU SCRIPT +# ============================================================================ \ No newline at end of file