diff --git a/functions/logs.sh b/functions/logs.sh index ecca143c0..83c80437d 100644 --- a/functions/logs.sh +++ b/functions/logs.sh @@ -1,21 +1,31 @@ #!/bin/bash # LGSM logs.sh function # Author: Daniel Gibbs +# Contributor: UltimateByte # Website: http://gameservermanagers.com -lgsm_version="271215" +lgsm_version="100215" # Description: Acts as a log rotater, removing old logs. local modulename="Log Manager" +# Check if logfile variable and file exist, create logfile if it doesn't exist if [ -n "${consolelog}" ]; then if [ ! -e "${consolelog}" ]; then touch "${consolelog}" fi fi -# log manager will active if finds logs older than ${logdays} + +# Log manager will start the cleanup if it finds logs older than ${logdays} if [ $(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) -ne "0" ]; then fn_printdots "Starting" + # Set addon logs directories + sourcemodlogdir="${systemdir}/addons/sourcemod/logs" + ulxlogdir="${systemdir}/data/ulx_logs" + darkrplogdir="${systemdir}/data/darkrp_logs" + legacyserverlogdir="${rootdir}/log/server" + # Setting up counting variables + scriptcount="0" ; consolecount="0" ; gamecount="0" ; srcdscount="0" ; smcount="0" ; ulxcount="0" ; darkrpcount="0" ; legacycount="0" sleep 1 fn_printok "Starting" fn_scriptlog "Starting" @@ -25,39 +35,61 @@ if [ $(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) -ne "0" ]; then fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 echo -en "\n" + # Logging logfiles to be removed according to ${logdays}, counting and removing them + # Script logfiles + find "${scriptlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + scriptcount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${scriptlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + # SRCDS and unreal logfiles if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then find "${gamelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + gamecount=$(find "${gamelogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${gamelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; fi - find "${scriptlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + # Console logfiles if [ -n "${consolelog}" ]; then find "${consolelogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" - fi - if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then - gamecount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) - fi - scriptcount=$(find "${scriptlogdir}"/ -type f -mtime +${logdays}|wc -l) - echo "${consolelog}" - if [ -n "${consolelog}" ]; then consolecount=$(find "${consolelogdir}"/ -type f -mtime +${logdays}|wc -l) - else - consolecount=0 + find "${consolelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; fi - - count=$((${scriptcount} + ${consolecount})) - if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then - count=$((${scriptcount} + ${consolecount} + ${gamecount})) - else - count=$((${scriptcount} + ${consolecount})) + # Source addons logfiles + if [ "${engine}" == "source" ]; then + # SourceMod logfiles + if [ -d "${sourcemodlogdir}" ]; then + find "${sourcemodlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + smcount=$(find "${sourcemodlogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${sourcemodlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + fi + # Garry's Mod logfiles + if [ "${gamename}" == "Garry's Mod" ]; then + # ULX logfiles + if [ -d "${ulxlogdir}" ]; then + find "${ulxlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + ulxcount=$(find "${ulxlogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${ulxlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + fi + # DarkRP logfiles + if [ -d "${darkrplogdir}" ]; then + find "${darkrplogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + darkrpcount=$(find "${darkrplogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${darkrplogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + fi + fi fi - - - if [ "${engine}" == "unreal2" ]||[ "${engine}" == "source" ]; then - find "${gamelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; - fi - find "${scriptlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; - if [ -n "${consolelog}" ]; then - find "${consolelogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + # Legacy support + if [ -d "${legacyserverlogdir}" ]; then + find "${legacyserverlogdir}"/ -type f -mtime +${logdays}|tee >> "${scriptlog}" + legacycount=$(find "${legacyserverlogdir}"/ -type f -mtime +${logdays}|wc -l) + find "${legacyserverlogdir}"/ -mtime +${logdays} -type f -exec rm -f {} \; + # Remove folder if empty + if [ ! "$(ls -A "${legacyserverlogdir}")" ]; then + rm -rf "${legacyserverlogdir}" + fi fi + + # Count total amount of files removed + count=$((${scriptcount} + ${consolecount} + ${gamecount} + ${srcdscount} + ${smcount} + ${ulxcount} + ${darkrpcount} + ${legacycount})) + # Job done fn_printok "Removed ${count} log files" fn_scriptlog "Removed ${count} log files" sleep 1