Skip to content

Instantly share code, notes, and snippets.

@robotamer
Last active December 30, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robotamer/7756415 to your computer and use it in GitHub Desktop.
Save robotamer/7756415 to your computer and use it in GitHub Desktop.
Log file rotate bash script
#!/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