#!/bin/sh
# timer to clean some big logs
#
# Copyright (C) 2006-2011  mariodebian at gmail
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#


# empty file if size is more than 52 Kb
MAX_SIZE=52

while [ 1 ]; do

  for file in $(find /var/log/ -type f); do
    size=$(du -a $file| awk '{print $1}')
    if [ $size -gt $MAX_SIZE ]; then
       logger "clear-logs $file have BIG size $size Kb, empty it"
       last_line=$(tail -1 $file)
       echo $last_line > $file
    fi
  done
  sleep 60
done
