sexta-feira, 29 de novembro de 2013

Script para efetuar ROTATE nos Logs do Squid ( Linux )


#!/bin/sh
# -----------------------------------------------------------------------------
    logzip() {
      for FILE in $1
       do
          [ -f ${LOG}/${FILE} ] && chmod 0600 ${LOG}/${FILE}
          if [ -f ${LOG}/${FILE}.1 ]
             then
                  gzip -f ${LOG}/${FILE}.1
                  if [ -f ${LOG}/${FILE}.1.gz ]
                     then
                           mv ${LOG}/${FILE}.1.gz ${LOG}/${FILE}.1
                           chown ${RID} ${LOG}/${FILE}.1
                           chgrp ${GID} ${LOG}/${FILE}.1
                           chmod  0600  ${LOG}/${FILE}.1
                     fi
             fi
      done
    }
# -----------------------------------------------------------------------------
#  SQUID ROTATE LOGS **********************************************************
# -----------------------------------------------------------------------------
   PATH="${PATH}:/usr/scripts"
   PATH="${PATH}:/usr/local/bin"
   export PATH
#
   ACC="access.log" # access log
   CAC="cache.log" # cache log
   STO="store.log" # store log
   ARQ="${ACC} ${CAC} ${STO}" # all files logs
   RID="squid" # cache user
   GID="webcache" # cache group
   LOG="/usr/local/squid/logs" # directory logs
   PD=`cat /var/run/squid.pid` # Process ID file
   MINLAP=82800                                 # 23:00 hours
   RMFILE=".last.rotation"                      # last rotation mark file
#
# -----------------------------------------------------------------------------
#  MAIN CODE ... **************************************************************
# -----------------------------------------------------------------------------
#
   [ -z "${PD}" ] && exit
   REF="${LOG}/${CAC}"
   MRK="${LOG}/${RMFILE}"
   AUX=`expr ${MINLAP:-0} + 1 2> /dev/null`

   if [ -f "${MRK}" ]
      then
            AUX=`getftime "${MRK}" 2> /dev/null | \
                 awk '{print $3}'`
            AUX=`expr ${AUX:-0} + 0 2> /dev/null`
      fi

   [ ${AUX:-0} -le ${MINLAP:-0} ] && exit
   cp  -p "${REF}" "${MRK}" 2> /dev/null
   cat /dev/null > "${MRK}" 2> /dev/null
   /usr/scripts/stop.fw
   /usr/local/squid/bin/squidlog 2> /dev/null
   kill -USR1 ${PD}
   sleep 60
   /usr/scripts/start.fw
   logzip ${ARQ}
# -----------------------------------------------------------------------------

Nenhum comentário:

Postar um comentário