Line # Revision Author
1 8 ahitrov@rambler.ru #!/bin/sh
2
3 LOGSDIR=`echo "$1" | sed -E 's#/+$##'`
4
5 if [ -z "$1" -o \! -d $1 ]; then
6 echo "ERROR: invalid logs directory '$1'"
7 exit 1
8 fi
9
10 STARTED=`date +%s`
11 TODAY=`date -jr $STARTED +%Y/%m/%d`
12 COUNT=0
13
14 echo -e "\nStarted at "`date -jr $STARTED`
15
16 for LOG in `cd $LOGSDIR && find -E ./ -type f \
17 -regex '^\./[[:digit:]]{4}/[[:digit:]]{2}/[[:digit:]]{2}/[^/]+$' | \
18 egrep -v '\.gz$' | egrep -v "^\./$TODAY/" | sed -E 's#^\./##' | sort`; do
19 echo "Compressing: $LOGSDIR/$LOG"
20 gzip $LOGSDIR/$LOG
21 echo " Done"
22 COUNT=$(($COUNT + 1))
23 done
24
25 find -L $LOGSDIR -type l -exec rm {} \;
26
27 FINISHED=`date +%s`
28 echo -e "Finished at "`date -jr $FINISHED`", compressed $COUNT logs, elapsed "$(($FINISHED - $STARTED))" seconds"