X-Git-Url: https://hackdaworld.org/gitweb/?p=scripts%2Fscripts.git;a=blobdiff_plain;f=logrotate.sh;h=b97a9d8e831e74bc87073dab0f47128c713ac02b;hp=d694981785ff03ae6e6819878d36e345a8de37ac;hb=HEAD;hpb=57f23cb7c6f8e527220ea8a2aa2f21c41c1f6dea diff --git a/logrotate.sh b/logrotate.sh index d694981..b97a9d8 100755 --- a/logrotate.sh +++ b/logrotate.sh @@ -2,19 +2,23 @@ # rotate the messages file if >= 4M -if [ -f /var/log/messages ] ; then -mess_size=`du -h /var/log/messages | sed 's/\/var\/log\/messages//' | sed 's/.*k/0/' | awk -F. '{ print $1 }'` -if [ "$mess_size" -gt "3" ] ; then - d_stamp=`date | awk '{ print $3 "-" $2 "-" $6 }'` - mv /var/log/messages /var/log/messages-${d_stamp} - gzip /var/log/messages-${d_stamp} - echo "rotated /var/log/messages file." -fi -fi +dodel=0 -if [ ! -f /var/log/messages ] ; then - touch /var/log/messages - echo "touched new /var/log/messages file." - /etc/init.d/syslogd restart -fi +logpaths="/var/log /var/opt/apache2/logs" +for i in `find $logpaths -size +3M`; do + rm -f ${i}.bz2 + bzip2 $i + echo "rotated $i file, touching empty file." + [ ! -f $i ] && touch $i + dodel=1 +done +if [ "$dodel" = "1" ] ; then + echo "rotated files, restarting some services ..." + /etc/init.d/sysklogd stop + /etc/init.d/apache stop + sleep 2 + /etc/init.d/sysklogd start + /etc/init.d/apache start + echo "done." +fi