linux-helferlein-scripte/cleaning/logs-delete.v1.sh

22 lines
665 B
Bash
Raw Permalink Normal View History

2024-03-02 14:27:13 +00:00
#!/bin/bash
# Script Name: logs-delete.v1.sh
# Beschreibung: deletes logs that are older than a specified time period
# Aufruf: bash ./logs-delete.v1.sh
# Autor: Patrick Asmus
# Web: https://www.media-techport.de
# Git-Reposit.: https://git.media-techport.de/scriptos/linux-helferlein-scripte.git
2024-03-02 14:28:10 +00:00
# Version: 1.0.1
2024-03-02 14:27:13 +00:00
# Datum: 02.03.2024
2024-03-02 14:28:10 +00:00
# Modifikation: wording adapted
2024-03-02 14:27:13 +00:00
#####################################################
2024-03-02 14:28:10 +00:00
# Variablen
2024-03-02 14:27:13 +00:00
LOG_DIR="/var/log"
DAYS_TO_KEEP=60
2024-03-02 14:28:10 +00:00
# lösche alte Log Files
2024-03-02 14:27:13 +00:00
find "$LOG_DIR" -type f -mtime +"$DAYS_TO_KEEP" -delete
2024-03-02 14:28:10 +00:00
# lösche Verzeichnisse, falls leer
2024-03-02 14:27:13 +00:00
find "$LOG_DIR" -type d -empty -delete
exit