61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
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
|
|
# ============================================================================ |