#!/bin/sh

# Archive yesterday logs
# Written by Georgi Chorbadzhiyski

PATH="/bin:/sbin:/usr/bin:/usr/sbin"

[ -z "$1" ] && {
    echo "Usage: `basename $0` log_directory"
    exit 1
}

logdir=$1
cd $logdir
[ $? = 0 ] || exit

dateformat="+%Y-%m-%d"
cdate=$(date $dateformat --date "1 day ago" )

echo "Archiving logs for $cdate (now: `date`)"
for log in `ls $logdir/*/$cdate/* | grep -v ".gz$"`; do
    if [ -f $log ]; then
	echo $log
	gzip -9 $log
    fi
done
echo "Done."
