diff --git a/README.md b/README.md index fced07e..651398f 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,39 @@ -# Logrotate Automation Script - -This simple Bash script automates the execution of `logrotate` for specific log files, ensuring that your logs are managed effectively to prevent disk space issues and improve system performance. +Absolut\! Hier ist eine schöne `README.md` auf Deutsch für dein Skript: ----- -## Features +# Logrotate Automatisierungsskript - * **Automated Log Rotation**: Automatically runs `logrotate` with a specified configuration. - * **Status Tracking**: Utilizes a status file to keep track of the last rotation times. - * **Error Handling**: Checks for the existence of the configuration file and logs errors if it's missing. - * **Logging**: Records the execution status and any errors to a dedicated log file. +Dieses einfache Bash-Skript automatisiert die Ausführung von `logrotate` für spezifische Logdateien. Es stellt sicher, dass deine Logs effektiv verwaltet werden, um Problemen mit dem Festplattenspeicher vorzubeugen und die Systemleistung zu verbessern. ----- -## Getting Started +## Funktionen -These instructions will help you set up and run the script on your system. + * **Automatisierte Log-Rotation**: Führt `logrotate` automatisch mit einer spezifischen Konfiguration aus. + * **Statusverfolgung**: Verwendet eine Statusdatei, um die Zeiten der letzten Rotationen zu verfolgen. + * **Fehlerbehandlung**: Prüft das Vorhandensein der Konfigurationsdatei und protokolliert Fehler, falls diese fehlt. + * **Protokollierung**: Zeichnet den Ausführungsstatus und eventuelle Fehler in einer dedizierten Logdatei auf. -### Prerequisites +----- - * **`logrotate`**: This utility is typically pre-installed on most Linux distributions. If not, you can install it using your system's package manager (e.g., `sudo apt-get install logrotate` on Debian/Ubuntu, `sudo yum install logrotate` on CentOS/RHEL). +## Erste Schritte + +Diese Anweisungen helfen dir, das Skript auf deinem System einzurichten und auszuführen. + +### Voraussetzungen + + * **`logrotate`**: Dieses Dienstprogramm ist in der Regel auf den meisten Linux-Distributionen vorinstalliert. Falls nicht, kannst du es mit dem Paketmanager deines Systems installieren (z.B. `sudo apt-get install logrotate` unter Debian/Ubuntu, `sudo yum install logrotate` unter CentOS/RHEL). ### Installation -1. **Save the Script**: Copy the provided script content into a file (e.g., `run_logrotate.sh`) in your desired directory. -2. **Make Executable**: Grant execute permissions to the script: +1. **Skript speichern**: Kopiere den Inhalt des bereitgestellten Skripts in eine Datei (z.B. `run_logrotate.sh`) in deinem gewünschten Verzeichnis. +2. **Ausführbar machen**: Gib dem Skript Ausführungsberechtigungen: ```bash chmod +x run_logrotate.sh ``` -3. **Create Configuration**: Create a `logrotate.cfg` file in the same directory as the script. This file will contain your `logrotate` rules. -4. **Create Log and Status Files**: The script will create these if they don't exist, but you can create empty ones manually if you prefer: +3. **Konfiguration erstellen**: Erstelle eine Datei `logrotate.cfg` im selben Verzeichnis wie das Skript. Diese Datei enthält deine `logrotate`-Regeln. +4. **Log- und Statusdateien erstellen**: Das Skript erstellt diese, falls sie nicht existieren, aber du kannst auch leere Dateien manuell erstellen, wenn du möchtest: ```bash touch logrotate.status touch logrotate.log @@ -37,11 +41,11 @@ These instructions will help you set up and run the script on your system. ----- -## Usage +## Verwendung -### Configuration (`logrotate.cfg`) +### Konfiguration (`logrotate.cfg`) -The `logrotate.cfg` file defines how your logs should be rotated. Here's a basic example: +Die Datei `logrotate.cfg` definiert, wie deine Logs rotiert werden sollen. Hier ist ein einfaches Beispiel: ``` /var/log/my_app/*.log { @@ -55,54 +59,54 @@ The `logrotate.cfg` file defines how your logs should be rotated. Here's a basic } ``` - * Replace `/var/log/my_app/*.log` with the actual path to your log files. - * `daily`: Rotate logs daily. - * `rotate 7`: Keep 7 rotated log files. - * `compress`: Compress old log files. - * `missingok`: Don't issue an error if the log file is missing. - * `notifempty`: Don't rotate the log if it is empty. - * `create 640 root adm`: Create new log files with specified permissions and ownership. - * `dateext`: Archive rotated logs by adding a date extension. + * Ersetze `/var/log/my_app/*.log` durch den tatsächlichen Pfad zu deinen Logdateien. + * `daily`: Rotiert Logs täglich. + * `rotate 7`: Behält 7 rotierte Logdateien. + * `compress`: Komprimiert alte Logdateien. + * `missingok`: Gibt keinen Fehler aus, wenn die Logdatei fehlt. + * `notifempty`: Rotiert das Log nicht, wenn es leer ist. + * `create 640 root adm`: Erstellt neue Logdateien mit den angegebenen Berechtigungen und Eigentümer. + * `dateext`: Archiviert rotierte Logs, indem eine Datums-Erweiterung hinzugefügt wird. -For more details on `logrotate` configuration, refer to the `logrotate` man page (`man logrotate`). +Weitere Details zur `logrotate`-Konfiguration findest du in der `logrotate`-Manpage (`man logrotate`). -### Running the Script +### Ausführen des Skripts -You can run the script manually: +Du kannst das Skript manuell ausführen: ```bash ./run_logrotate.sh ``` -### Automation (Cron Job) +### Automatisierung (Cron-Job) -To automate log rotation, it's recommended to set up a cron job. +Um die Log-Rotation zu automatisieren, wird empfohlen, einen Cron-Job einzurichten. -1. Open your crontab for editing: +1. Öffne deine Crontab zur Bearbeitung: ```bash crontab -e ``` -2. Add a line to execute the script at your desired interval. For example, to run it daily at 3:00 AM: +2. Füge eine Zeile hinzu, um das Skript in deinem gewünschten Intervall auszuführen. Zum Beispiel, um es täglich um 3:00 Uhr morgens auszuführen: ```cron 0 3 * * * /home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh >> /dev/null 2>&1 ``` - Make sure to replace `/home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh` with the actual full path to your script. The `>> /dev/null 2>&1` part redirects standard output and error to `/dev/null` to prevent unnecessary emails from cron. + Stelle sicher, dass du `/home/oberkoetter/Dokumente/Git/rettedpv/run_logrotate.sh` durch den tatsächlichen vollständigen Pfad zu deinem Skript ersetzt. Der Teil `>> /dev/null 2>&1` leitet die Standardausgabe und Fehler nach \`/dev/null um, um unnötige E-Mails von Cron zu verhindern. ----- -## Script Details +## Skript-Details -The script performs the following actions: +Das Skript führt die folgenden Aktionen aus: -1. **Changes Directory**: Navigates to `/home/oberkoetter/Dokumente/Git/rettedpv`. **Note:** You might want to adjust this path if you move the script. -2. **Defines Paths**: Sets variables for the `logrotate.cfg`, `logrotate.status`, and `logrotate.log` files within the current working directory. -3. **Checks Configuration**: Verifies if `logrotate.cfg` exists. If not, it logs an error and exits. -4. **Executes Logrotate**: Runs `logrotate` in forced mode (`-f`) using the specified configuration and status files. -5. **Logs Success**: Appends a success message to `logrotate.log` after a successful execution. +1. **Verzeichnis wechseln**: Navigiert nach `/home/oberkoetter/Dokumente/Git/rettedpv`. **Hinweis:** Diesen Pfad solltest du anpassen, falls du das Skript verschiebst. +2. **Pfade definieren**: Setzt Variablen für die Dateien `logrotate.cfg`, `logrotate.status` und `logrotate.log` innerhalb des aktuellen Arbeitsverzeichnisses. +3. **Konfiguration prüfen**: Überprüft, ob `logrotate.cfg` existiert. Falls nicht, wird ein Fehler protokolliert und das Skript beendet. +4. **Logrotate ausführen**: Führt `logrotate` im erzwungenen Modus (`-f`) unter Verwendung der angegebenen Konfigurations- und Statusdateien aus. +5. **Erfolg protokollieren**: Fügt eine Erfolgsmeldung zur Datei `logrotate.log` hinzu, nachdem eine erfolgreiche Ausführung stattgefunden hat. ----- -## Project Structure +## Projektstruktur ``` . @@ -112,17 +116,17 @@ The script performs the following actions: └── logrotate.status ``` - * `run_logrotate.sh`: The main script to execute logrotate. - * `logrotate.cfg`: The configuration file for logrotate. - * `logrotate.log`: Logs the execution history of the script. - * `logrotate.status`: Logrotate's internal status file. + * `run_logrotate.sh`: Das Hauptskript zur Ausführung von logrotate. + * `logrotate.cfg`: Die Konfigurationsdatei für logrotate. + * `logrotate.log`: Protokolliert die Ausführungshistorie des Skripts. + * `logrotate.status`: Logrotates interne Statusdatei. ----- -## Troubleshooting +## Fehlerbehebung - * **"Fehler: Konfigurationsdatei './logrotate.cfg' nicht gefunden."**: Ensure `logrotate.cfg` is in the same directory as the script or update the `CONFIG` variable in the script to the correct path. - * **Script not running via cron**: Double-check the cron job entry for correct paths and permissions. You can test by manually running the script. Also, check your `logrotate.log` for any errors. - * **Log files not rotating**: Verify your `logrotate.cfg` syntax. You can test your `logrotate` configuration directly using `logrotate -d your_config_file` (debug mode) or `logrotate -f your_config_file` (force mode). + * **"Fehler: Konfigurationsdatei './logrotate.cfg' nicht gefunden."**: Stelle sicher, dass `logrotate.cfg` sich im selben Verzeichnis wie das Skript befindet, oder aktualisiere die Variable `CONFIG` im Skript auf den korrekten Pfad. + * **Skript wird nicht über Cron ausgeführt**: Überprüfe den Cron-Job-Eintrag auf korrekte Pfade und Berechtigungen. Du kannst dies testen, indem du das Skript manuell ausführst. Prüfe auch deine `logrotate.log` auf Fehler. + * **Logdateien werden nicht rotiert**: Überprüfe die Syntax deiner `logrotate.cfg`. Du kannst deine `logrotate`-Konfiguration direkt testen, indem du `logrotate -d deine_konfigurationsdatei` (Debug-Modus) oder `logrotate -f deine_konfigurationsdatei` (Erzwingungsmodus) verwendest. ----- \ No newline at end of file