Created
January 18, 2017 01:01
-
-
Save johnrichardrinehart/dcf2b7ab7b1a8485c8d079fe378bcfd0 to your computer and use it in GitHub Desktop.
ZNC log cleanup (cleans up messages and old logs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DATE=`date +%Y-%m-%d--%H:%M:%S`; | |
ZNCCLEANDIR=/home/john/znc_clean; | |
ZNCLOGDIR=/home/john/.znc/users/fuzzybear3965/networks/lovelace_freenode/moddata/log; | |
MESSAGESFILENAMERELATIVE="messages_$DATE.log"; | |
OLDLOGSFILENAMERELATIVE="oldlogs_$DATE.log"; | |
MESSAGESFILENAME=$ZNCCLEANDIR/$MESSAGESFILENAMERELATIVE; | |
OLDLOGSFILENAME=$ZNCCLEANDIR/$OLDLOGSFILENAMERELATIVE; | |
if [ -f $MESSAGESFILENAME ]; then | |
mv $MESSAGESFILENAME $MESSAGESFILENAME.bkp; | |
fi | |
cd $ZNCLOGDIR; | |
find $ZNCLOGDIR -mindepth 1 -maxdepth 1 -type d ! -name "#*" | | |
while read messagesdir; | |
do echo $messagesdir >> $MESSAGESFILENAME; | |
cd $messagesdir; | |
cat *.log >> $MESSAGESFILENAME; | |
cd ..; | |
rm -rf $messagesdir; | |
done | |
# compress and move channel folders older than 7 days | |
find $ZNCLOGDIR -mindepth 1 -maxdepth 1 -type d -name "#*" -ctime +7 | | |
while read oldlogdir; | |
do echo $oldlogdir >> $MESSAGESFILENAME; | |
cd $oldlogdir; | |
cat *.log >> $MESSAGESFILENAME; | |
cd ..; | |
rm -rf $oldlogdir; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment