Logrotate-Konfigurations-Skript – Kurzanleitung

Veröffentlichung 3. August 2018 @ 15:27
Letzte Änderung 3. August 2018 @ 15:27

Überblick

  • Erzeugen von Logrotate-Konfigurationsdateien

Voraussetzungen

Netzwerk

  • Benutzer root

Software

  • Ubuntu Server 16.04.04 LTS #lsb_release -a

Ordner und Dateien

  • Konfiguration /etc/logrotate.d/example
  • Log /root/logs/example.log*
  • Skript /root/scripts/create_logrotate.sh

Bash-Skript zum Anlegen von Logrotate-Konfigurationsdateien erstellen

Logrotate-Skript anlegen

#!/bin/bash
LOGFILE=$1 #Logdatei
CONFIGFILE=$2 #Konfigurationsdatei
CONFIGDIR=/etc/logrotate.d #Konfigurationsverzeichnis
rm --force $CONFIGDIR/$CONFIGFILE
touch $CONFIGDIR/$CONFIGFILE
echo "$LOGFILE {" >> $CONFIGDIR/$CONFIGFILE
echo "  daily" >> $CONFIGDIR/$CONFIGFILE
echo "  missingok" >> $CONFIGDIR/$CONFIGFILE
echo "  nocompress" >> $CONFIGDIR/$CONFIGFILE
echo "  notifempty" >> $CONFIGDIR/$CONFIGFILE
echo "  rotate 7" >> $CONFIGDIR/$CONFIGFILE
echo "}" >> $CONFIGDIR/$CONFIGFILE

Zugriffsrechte anpassen

chmod 0700 /root/scripts/create_logrotate.sh

Beispiel

Logdatei /root/log/example.log rotieren

/root/scripts/create_logrotate.sh /root/logs/example.log example

Quellen

http://manpages.ubuntu.com/manpages/xenial/man8/logrotate.8.html
https://www.gnu.org/software/bash/manual/

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert