Skip to content

Instantly share code, notes, and snippets.

@Opfour
Last active January 20, 2022 20:59
Show Gist options
  • Save Opfour/aca5eff9333948e26d09331ec6dfd43b to your computer and use it in GitHub Desktop.
Save Opfour/aca5eff9333948e26d09331ec6dfd43b to your computer and use it in GitHub Desktop.
#!/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