Last active
January 20, 2022 20:59
-
-
Save Opfour/aca5eff9333948e26d09331ec6dfd43b to your computer and use it in GitHub Desktop.
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 | |
timestamp=`date +%Y%m%d` | |
LOGDIR=/var/log/log.foo | |
find $LOGDIR -name '*.log' -type f -size +512k | while read logfile | |
do # the parsing of a line | |
echo $logfile | |
newlogfile=$logfile.$timestamp | |
cp $logfile $newlogfile | |
cat /dev/null > $logfile | |
gzip -f -9 $newlogfile | |
done | |
#Delete logs older than 90 days: | |
find $LOGDIR -name '*.gz' -type f -mtime 90 |xargs rm -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment