You've already forked journal-log-ubuntu
initial commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal 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.
|
||||||
47
README.md
Normal file
47
README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Clear Journal Log for Ubuntu 24.04 Server
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](#)
|
||||||
|
[](./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).
|
||||||
|
|
||||||
|
---
|
||||||
54
journal-log-ubuntu
Executable file
54
journal-log-ubuntu
Executable file
@@ -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 <<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/bin/clear-journal-log
|
||||||
|
|
||||||
|
#
|
||||||
|
# Restart cron
|
||||||
|
#
|
||||||
|
systemctl restart cron.service
|
||||||
|
|
||||||
|
#
|
||||||
|
# All done
|
||||||
|
#
|
||||||
|
printf "\nAll Done...\n"
|
||||||
|
|
||||||
|
#
|
||||||
|
# End of script
|
||||||
|
#
|
||||||
4
last-tested
Normal file
4
last-tested
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
------------------------------------
|
||||||
|
Last tested: 15-10-2025 (DD-MM-YYYY)
|
||||||
|
Environment: Ubuntu Server 24.04 LTS
|
||||||
|
------------------------------------
|
||||||
Reference in New Issue
Block a user