latest commit

This commit is contained in:
2025-12-19 15:14:22 +01:00
commit ec66763f53
4 changed files with 190 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -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.

104
README.md Normal file
View File

@@ -0,0 +1,104 @@
# Journal Log Auto-Cleanup 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)
Auto-cleanup systemd journal logs on Ubuntu 24.04 server.
This is not a test script.
This is designed for stable long-term use with predictable disk usage.
## Why this installer exists
System logs grow silently until they cause trouble. This prevents that automatically.
## What this installer does
✔ Weekly rotation + vacuum cleanup
✔ Keeps only last 3 days of logs
✔ Lightweight, hands-off operation
✔ Fully automated via cron
## What this installer does *NOT* do
It wont stop you from running the script without reading the documentation like theres no tomorrow.
Skip the README, and whatever happens next is your headache, not a bug report.
---
## 1. Download
```
git clone https://git.x-files.dk/server/journal-log-ubuntu.git
```
```
cd journal-log-ubuntu
```
---
## 2. Install
```
sudo ./journal-log-ubuntu
```
This creates a cron-executed cleanup script at:
```
/usr/local/sbin/clear-journal-log
```
and registers a weekly schedule under:
```
/etc/cron.d/clear-journal-log
```
---
## 3. Schedule Details
Cleanup runs automatically:
| Action | When |
|---|---|
| Journal rotation + vacuum | Every Sunday @ 02:00 |
| Log retention window | 3 days |
| Output log | `/var/log/clear-journal.log` |
You don't need to add cron jobs — installer handles everything.
---
## 4. Verify Log Rotation
Check last run:
```
cat /var/log/clear-journal.log
```
You should see:
✔ size before cleanup
✔ size after cleanup
✔ timestamped header + footer
---
### Post-Install
Nothing else required — scheduling is automatic.
---
### 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).
---

61
journal-log-ubuntu Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Author : Allan Christensen
# First Created : 23-11-2021 (DD-MM-YYYY)
# Description : Clears the journal log once a week on Ubuntu 24.04
# License : MIT License
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then printf "\nMust be root or use sudo!\n\n"; exit; fi
#
# Create cron job
#
cronjob01="0 2 * * 7 root /usr/local/sbin/clear-journal-log >/dev/null 2>&1"
echo "$cronjob01" > /etc/cron.d/clear-journal-log
echo "" >> /etc/cron.d/clear-journal-log
#
# Ensure correct permissions for /etc/cron.d entries
#
chmod 644 /etc/cron.d/clear-journal-log
chown root:root /etc/cron.d/clear-journal-log
#
# Create script to clear the journal log executed by cron
#
cat > /usr/local/sbin/clear-journal-log <<EOF
#!/usr/bin/env bash
logfile="/var/log/clear-journal.log"
line () { for i in {1..100}; do echo -n "$1"; done && printf "\n"; }
datenow=$(date +"%d-%m-%Y %H:%M")
# Clear journal log
line '-' > "$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/sbin/clear-journal-log
#
# Restart cron
#
systemctl restart cron.service
#
# All done
#
printf "\nAll Done...\n"
#
# End of script
#

4
last-tested Normal file
View File

@@ -0,0 +1,4 @@
------------------------------------
Last tested: 19-12-2025 (DD-MM-YYYY)
Environment: Ubuntu Server 24.04 LTS
------------------------------------