initial commit
This commit is contained in:
commit
249ba1d438
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -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.
|
25
README.md
Normal file
25
README.md
Normal file
@ -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.
|
60
clear-journal-log
Executable file
60
clear-journal-log
Executable file
@ -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
|
||||
#
|
Loading…
Reference in New Issue
Block a user