Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a daily cronjob emergency deletion of logs/files #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lepidopter-fh/etc/cron.daily/emergency_cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# This script will cleanup old log files and apt cache if a specific warning or
# critical percentage of used disk space is triggered for the root filesystem
set -e

# Critical percentage of root filesystem usage
CRITICAL_PCENT=98
# Warning percentage of root filesystem usage
WARNING_PCENT=93
ROOTFS_USE=$(df --sync --output=pcent / |tail -n1 |cut -d'%' -f1 |tr -d ' ')

if [ "$ROOTFS_USE" -ge "$CRITICAL_PCENT" ] ; then
apt-get clean
echo "Removing documentation..." >&2
find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true
find /usr/share/doc -empty|xargs rmdir || true
rm -rf /usr/share/man /usr/share/groff /usr/share/info /usr/share/lintian \
/usr/share/linda /var/cache/man /usr/share/locale
find /var/log/ -type f -mtime +1 -exec rm -f -- '{}' \;
elif [ "$ROOTFS_USE" -ge "$WARNING_PCENT" ] ; then
# Remove the same set of files and directories
find /var/log/ -type f -mtime +2 -exec rm -f -- '{}' \;
fi