]> hackdaworld.org Git - scripts/scripts.git/commitdiff
add more logfiles to rotate
authorhackbard <hackbard>
Fri, 19 Nov 2004 12:27:35 +0000 (12:27 +0000)
committerhackbard <hackbard>
Fri, 19 Nov 2004 12:27:35 +0000 (12:27 +0000)
logrotate.sh

index b6bd553cd060bfad4bd748a4b317ff9e10d0b807..9938c80c0e52c124d5117080b07a97e098b2d684 100755 (executable)
@@ -2,19 +2,27 @@
 
 # rotate the messages file if >= 4M
 
-if [ -f /var/log/messages ] ; then
-mess_size=`du -h /var/log/messages | awk '{ print $1 }' | sed 's/.*k/0/' | awk -F. '{ print $1 }'`
-if [ "$mess_size" -gt "3" ] ; then
-       rm -f /var/log/messages.bz2
-       bzip2 /var/log/messages
-       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/sysklogd stop
-       /etc/init.d/sysklogd start
-fi
+for i in /var/log/messages /var/log/sys.log /var/opt/apache2/logs/access_log /var/opt/apache2/logs/error_log; do
+  if [ -f $i ] ; then
+    mess_size=`du -h $i | awk '{ print $1 }' | sed 's/.*k/0/' | awk -F. '{ print $1 }'`
+    if [ "$mess_size" -gt "3" ] ; then
+      rm -f ${i}.bz2
+      bzip2 $i
+      echo "rotated $i file, touching empty file."
+      [ ! -f $i ] && touch $i
+      dodel=1
+    fi
+  fi
+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