MAJ SG
This commit is contained in:
61
Vider_Logs.py
Normal file
61
Vider_Logs.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import paramiko
|
||||
# Configuration
|
||||
hostname = "162.19.78.131"
|
||||
port = 22
|
||||
username = "debian"
|
||||
password = "lpZwixbBUFtGY"
|
||||
chemin_script = "/home/debian/Gestion_sondes/app/Vider_Logs.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
|
||||
# ============================================================================
|
||||
Reference in New Issue
Block a user