commit 3da527c55703caae89f516ad669c406e1fae6817 Author: allan Date: Thu Oct 23 15:40:29 2025 +0200 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3eaaa81 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc5893f --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Clear Journal Log for Ubuntu 24.04 Server +[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#) +[![Shell](https://img.shields.io/badge/shell-bash-121011)](#) +[![Feature](https://img.shields.io/badge/feature-journal_cleanup-0078D7)](#) +[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE) + +Automated Bash installer script for configuring **journal log cleanup** on Ubuntu 24.04 Server. + +This script automatically cleans up **journalctl** once a week, retaining logs for **3 days**. + +### Download the Script +Clone the repository from your Git server: + +``` +git clone https://git.x-files.dk/server/journal-log-ubuntu.git +``` + +``` +cd journal-log-ubuntu +``` + +### Usage +Run the script using: + +``` +cd journal-log-ubuntu +sudo ./journal-log-ubuntu +``` + +### Notes +A crontab entry will be added to perform cleanup of **journalctl** logs. This job runs every **Sunday at 02:00**. + +### Post-install +Nothing to do. + +--- + +### More Information + +More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk) + +--- + +### License +Licensed under the [MIT License](./LICENSE). + +--- diff --git a/journal-log-ubuntu b/journal-log-ubuntu new file mode 100755 index 0000000..4afb025 --- /dev/null +++ b/journal-log-ubuntu @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Author : Allan Christensen +# First Created : 23112021 (DD-MM-YYYY) +# Description : Clears the journal log once a week on Ubuntu 24.04 +# License : MIT License (see LICENSE file for details) + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then printf "\nMust be root or use sudo!\n\n"; exit; fi + +# +# Create cronjob +# +cronjob01="0 2 * * 7 root /usr/local/bin/clear-journal-log >/dev/null 2>&1" +echo "$cronjob01" > /etc/cron.d/clear-journal-log + +# +# Create clear journal log script to be executed by cron +# +cat > /usr/local/bin/clear-journal-log < "$logfile" +diskusage=$(journalctl --disk-usage) +printf "%s Before Cleanup: %s\n" "$datenow" "$diskusage" >> "$logfile" +journalctl --rotate >/dev/null 2>&1 +journalctl --vacuum-time=3d >/dev/null 2>&1 +diskusage=$(journalctl --disk-usage) +printf "%s After Cleanup: %s\n" "$datenow" "$diskusage" >> "$logfile" +line '-' >> "$logfile" +EOF + +chmod 755 /usr/local/bin/clear-journal-log + +# +# Restart cron +# +systemctl restart cron.service + +# +# All done +# +printf "\nAll Done...\n" + +# +# End of script +# diff --git a/last-tested b/last-tested new file mode 100644 index 0000000..3f1f6ef --- /dev/null +++ b/last-tested @@ -0,0 +1,4 @@ +------------------------------------ +Last tested: 15-10-2025 (DD-MM-YYYY) +Environment: Ubuntu Server 24.04 LTS +------------------------------------