From e34ca9aa8799091d89de5726902a6b67fdceb1ed Mon Sep 17 00:00:00 2001 From: archos Date: Wed, 19 Jun 2024 20:25:33 +0200 Subject: [PATCH] =?UTF-8?q?p=C5=99id=C3=A1n=20skript,=20pro=20pravideln?= =?UTF-8?q?=C3=A9=20=C4=8Di=C5=A1t=C4=9Bn=C3=AD=20log=20soubor=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/clean_logs.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/clean_logs.sh diff --git a/scripts/clean_logs.sh b/scripts/clean_logs.sh new file mode 100644 index 0000000..547ad71 --- /dev/null +++ b/scripts/clean_logs.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Nastavení proměnných +LOG_DIR="/path/to/your/logs" +LOG_FILE="/path/to/your/logs/clean_logs.log" +DAYS_TO_KEEP=30 + +# Přepsání log souboru +echo "Starting log cleanup at $(date)" > $LOG_FILE + +# Vyčištění log souborů starších než zadaný počet dní +find $LOG_DIR -type f -name "*.log" -mtime +$DAYS_TO_KEEP -exec rm -f {} \; >> $LOG_FILE 2>&1 + +if [ $? -eq 0 ]; then + echo "Log cleanup completed successfully at $(date)" >> $LOG_FILE +else + echo "Error: Log cleanup failed at $(date)" >> $LOG_FILE + exit 1 +fi