logcleanup.sh

This is a quick script I put together for managing the logs that are created using LGSM (linux game server manager). There are a number of tasks that I have run automatically such as checking that connection is still up, checking for game server updates, and checking for LGSM updates. To accomplish this, I use several cron jobs which then pipe their output to a log file.

After running for a few months, these log files can become pretty large, so once a month I allow this script to run to delete and re-create all the log files so that they can be written to again:

This script will first check if ~/log/cron exists, and if not creates the directory, and touches the required files for the cron jobs to output to. If the folder already exists, it will delete all the files and touch them to be ready for cron.

!/bin/bash
touchFiles() {
touch ~/log/cron/backup.log
touch ~/log/cron/monitor.log
touch ~/log/cron/update.log
touch  ~/log/cron/update-lgsm.log
}

createDir() {
mkdir ~/log/cron
}

FILE1=~/log/cron

if [ -d "$FILE1" ]; then rm ~/log/cron/*.*
touchFiles
else
createDir
touchFiles
fi