Last active
December 30, 2015 01:29
-
-
Save robotamer/7756415 to your computer and use it in GitHub Desktop.
Log file rotate bash script
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 | |
MAXSIZE=90000 | |
LOGDIR=/var/www/log/ | |
cd $LOGDIR | |
for FILENAME in *.log; do | |
SIZE=$(du -b $FILENAME | cut -f 1) | |
if ($SIZE > $MAXSIZE); then | |
TIMESTAMP=`date +%Y%m%d` | |
NEWFILENAME=$FILENAME.$TIMESTAMP | |
cp $FILENAME $NEWFILENAME | |
gzip -f -9 $NEWFILENAME | |
rm $FILENAME | |
touch $FILENAME | |
chown www-data.tamer $FILENAME | |
chown tamer.www-data $NEWFILENAME.gz | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment