X-Git-Url: https://hackdaworld.org/gitweb/?p=scripts%2Fscripts.git;a=blobdiff_plain;f=logrotate.sh;fp=logrotate.sh;h=b6bd553cd060bfad4bd748a4b317ff9e10d0b807;hp=d694981785ff03ae6e6819878d36e345a8de37ac;hb=a8eb012e01ccb8f48275dea8c3b9998b2d45de8a;hpb=b5becb44003dc59c50cd84500ee34c26084f8a10 diff --git a/logrotate.sh b/logrotate.sh index d694981..b6bd553 100755 --- a/logrotate.sh +++ b/logrotate.sh @@ -3,11 +3,10 @@ # 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 }'` +mess_size=`du -h /var/log/messages | awk '{ print $1 }' | 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} + rm -f /var/log/messages.bz2 + bzip2 /var/log/messages echo "rotated /var/log/messages file." fi fi @@ -15,6 +14,7 @@ fi if [ ! -f /var/log/messages ] ; then touch /var/log/messages echo "touched new /var/log/messages file." - /etc/init.d/syslogd restart + /etc/init.d/sysklogd stop + /etc/init.d/sysklogd start fi