commit 249ba1d43806455d922dce7f6dc0cc6e22bf6b70 Author: allan Date: Thu Oct 24 12:37:34 2024 +0200 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..57f408b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 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..a505662 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +## Clear journal log + +### Prerequisites +Ubuntu 20.04 or higher. + +### Download the script +``` +git clone https://git.x-files.dk/ubuntu-server/clear-journal-log.git +``` + +### Usage + cd clear-journal-log + sudo ./clear-journal-log + +### Note + A crontab entry performing cleanup of journalctl will be added. This this job runs every Sunday at 02:00 + +### Postinstall +Nothing to do. + +### More guides +More guides can be found on [\[wiki.x-files.dk\]](https://wiki.x-files.dk) + +### Last tested +January 12th 2024 on Ubuntu 22.04. diff --git a/clear-journal-log b/clear-journal-log new file mode 100755 index 0000000..1e9a201 --- /dev/null +++ b/clear-journal-log @@ -0,0 +1,60 @@ +#!/bin/bash + +###################################################################### +# First Created: 23112022 Author: Allan Desc: Clears the journal log # +###################################################################### + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then printf "\nMust be root or use sudo!\n\n"; exit; fi +# +# Are we in the right directory +# +scriptdir="clear-journal-log" && whereami=$(pwd |awk -F'/' '{print $NF}') +if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n"; exit 1; fi +# +# Define variables and functions +# +cronjob01="0 2 * * 7 root /usr/local/bin/clear-journal-log >/dev/null 2>&1" +# +# Clear journal log script +# +script=" +#!/bin/bash + +###################################################################### +# First Created: 23112022 Author: Allan Desc: Clears the journal log # +###################################################################### + +# +# Define variables and functions +# +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 +" +# +# Create clear journal log script in /usr/local/bin +# +printf '%s\n' "${script[@]}" |sed '$d' |tail -n +2 > /usr/local/bin/clear-journal-log +chmod +x /usr/local/bin/clear-journal-log +echo "$cronjob01" > /etc/cron.d/clear-journal-log +# +# Restart cron +# +systemctl restart cron.service +# +# End of script +#