Minecraft Logdateien putzen

Mit diesem Skript lasse ich die Logdateien bereinigen.

Mit einem Editor das File minecraft_log_putzen erstellen. Ich habe es unter /home/minecraft/bin/ gespeichert.

mkdir -p /home/minecraft/bin/;nano /home/minecraft/bin/minecraft_log_putzen


#!/bin/bash
# ---------------------------------------------------------------------------
# minecraft_log_putzen - Bereinigung der Logdateien
# Copyright 2017, Christian Müller christian.mueller@elektro-fred.de
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at <http://www.gnu.org/licenses/> for
# more details.
# Usage: minecraft_log_putzen [-h|--help]
# Revision history:
# 2016-11-19 Created by new_script ver. 3.3
# ---------------------------------------------------------------------------
PROGNAME=${0##*/}
VERSION="1.0"
clean_up() { # Perform pre-exit housekeeping
return
}
error_exit() {
echo -e "${PROGNAME}: ${1:-"Unknown Error"}" >&2
clean_up
exit 1
}
graceful_exit() {
clean_up
exit
}
signal_exit() { # Handle trapped signals
case $1 in
INT)
error_exit "Program interrupted by user" ;;
TERM)
echo -e "\n$PROGNAME: Program terminated" >&2
graceful_exit ;;
*)
error_exit "$PROGNAME: Terminating on unknown signal" ;;
esac
}
usage() {
echo -e "Usage: $PROGNAME [-h|--help]"
}
help_message() {
cat <<- _EOF_ $PROGNAME ver. $VERSION Bereinigung der Logdateien $(usage) Options: -h, --help Display this help message and exit. _EOF_ return } # Trap signals trap "signal_exit TERM" TERM HUP trap "signal_exit INT" INT # Parse command-line while [[ -n $1 ]]; do case $1 in -h | --help) help_message; graceful_exit ;; -* | --*) usage error_exit "Unknown option $1" ;; *) echo "Argument $1 to process..." ;; esac shift done # Main logic # lock dirs/files LOCKDIR="/run/lock/minecraft_log_putzen" PIDFILE="${LOCKDIR}/minecraft_log_putzen.pid" # exit codes and text ENO_SUCCESS=0; ETXT[0]="ENO_SUCCESS" ENO_GENERAL=1; ETXT[1]="ENO_GENERAL" ENO_LOCKFAIL=2; ETXT[2]="ENO_LOCKFAIL" ENO_RECVSIG=3; ETXT[3]="ENO_RECVSIG" ### ### start locking attempt ### trap 'ECODE=$?; echo "[statsgen] Exit: ${ETXT[ECODE]}($ECODE)" >&2' 0
echo -n "[statsgen] Locking: " >&2
if mkdir "${LOCKDIR}" &>/dev/null; then
# lock succeeded, install signal handlers before storing the PID just in case
# storing the PID fails
trap 'ECODE=$?;
echo "[statsgen] Removing lock. Exit: ${ETXT[ECODE]}($ECODE)" >&2
rm -rf "${LOCKDIR}"' 0
echo "$$" >"${PIDFILE}"
# the following handler will exit the script upon receiving these signals
# the trap on "0" (EXIT) from above will be triggered by this trap's "exit" command!
trap 'echo "[statsgen] Killed by a signal." >&2
exit ${ENO_RECVSIG}' 1 2 3 15
echo "success, installed signal handlers"
else
# lock failed, check if the other PID is alive
OTHERPID="$(cat "${PIDFILE}")"
# if cat isn't able to read the file, another instance is probably
# about to remove the lock -- exit, we're *still* locked
# Thanks to Grzegorz Wierzowiecki for pointing out this race condition on
# http://wiki.grzegorz.wierzowiecki.pl/code:mutex-in-bash
if [ $? != 0 ]; then
echo "lock failed, PID ${OTHERPID} is active" >&2
exit ${ENO_LOCKFAIL}
fi
if ! kill -0 $OTHERPID &>/dev/null; then
# lock is stale, remove it and restart
echo "removing stale lock of nonexistant PID ${OTHERPID}" >&2
rm -rf "${LOCKDIR}"
echo "[statsgen] restarting myself" >&2
exec "$0" "$@"
else
# lock is valid and OTHERPID is active - exit, we're locked!
echo "lock failed, PID ${OTHERPID} is active" >&2
exit ${ENO_LOCKFAIL}
fi
fi
# Allgemeine Variablen für Logfiles
export TERM=${TERM:-dumb}
exec >>/var/log/minecraft_log_putzen.log 2>&1
echo
date
datum=`date +%Y_%0m_%0e`
###################################################################
#
# Hier "ordner" und "alter" anpassen
#
###################################################################
# Maximales alter der Minecraft-Logs in Tagen
ordner="/home/minecraft/minecraft/logs"
alter="7"
echo Bereinigen wird gestartet $datum
echo ------------------------------------------------
# ---------------------------------- GESAMT BACKUP ROUTINE
echo Minecraft-Logs bereinigen
echo Ordner wird auf $ordner gesetzt
echo Alter wird auf $alter gesetzt
echo
echo ------------------------------------------------
echo Dateien in $ordner werden auf Alter überprüft - max. $alter Tage
find $ordner -mtime +$alter -exec echo {} \;
find $ordner -mtime +$alter -exec rm -fr {} \;
echo ------------------------------------------------
# Maximales alter der Minecraft-Crashreports in Tagen
ordner="/home/minecraft/minecraft/crash-reports"
alter="30"
echo Bereinigen wird gestartet $datum
echo ------------------------------------------------
# ---------------------------------- GESAMT BACKUP ROUTINE
echo Minecraft-Crashreports bereinigen
echo Ordner wird auf $ordner gesetzt
echo Alter wird auf $alter gesetzt
echo
echo ------------------------------------------------
echo Dateien in $ordner werden auf Alter überprüft - max. $alter Tage
find $ordner -mtime +$alter -exec echo {} \;
find $ordner -mtime +$alter -exec rm -fr {} \;
echo ------------------------------------------------
graceful_exit

Danach noch ausführbar machen.
chmod +x /home/minecraft/bin/minecraft_log_putzen

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.