User Tools

Site Tools


linux:bash_clean_up_journal
#!/bin/bash
 
# You could put a cron entry in /etc/cron.d/cleanupjournal like this
# 0  2 * * 7     root    /usr/local/bin/cronscripts/cleanupjournal >/dev/null 2>&1"
# And then copy this script to /usr/local/bin/cronscripts/cleanupjournal
# Remember to restart cron i.e systemctl restart cron.service
 
logfile="/var/log/cleanupjournal.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 "$datenow Before Cleanup: $diskusage\n" >> $logfile
journalctl --rotate >/dev/null 2>&1
journalctl --vacuum-time=1d >/dev/null 2>&1
diskusage=$(journalctl --disk-usage)
printf "$datenow After  Cleanup: $diskusage\n" >> $logfile
line '-' >> $logfile
linux/bash_clean_up_journal.txt · Last modified: 12/01/2024 15:35 by Allan