On 8/13/08, Zbigniew Szalbot <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I fear it it not possible but I'll ask the experts anyway. Is it possible to 
> rotate apache logs based on size and time?
>
> I would like to rotate logs every 20MB AND at the start of the month 
> irrespective of the log size.
>
> Is it possible?

yes its possible
you would just need to add in your /etc/logrotate.conf  the following content :


"/websites/domain.com/logs/domain.com.sys.qualiproj.access_log"
/websites/domain.com/logs/domain.com.sys.qualiproj.error_log {
rotate 4
size= 50
sharedscripts
postrotate
/sbin/killall -HUP httpd
endscript
}

i kind of written a small scrit to add /delete /edit the
logrotate.conf for virtual domains (  i give no grauntee that it will
work for you ) ( suggestion welcomed )


#!/bin/bash
clear

add_log_rotation ()
{
read -p "Enter your domain name: " d
read -p "Enter the number of times you want logs to be rotated : " r
read -p "Enter the size of you log size " s

tmp=` echo $d |sed s/\.com//g `

config_file="/etc/logrotate.conf"

if [ -d /websites/"$d" ]; then

         if [  -z "$(sed -n
"/\#apache_logs_${d}\#/,/\#apache_logs_${d}\#/p" /etc/logrotate.conf)"
 ]; then

cat >> $config_file << _eof_
######################apache_logs_$d###########################
"/websites/$d/logs/$tmp.sys.qualiproj.access_log"
/websites/$d/logs/$tmp.sys.qualiproj.error_log {
           rotate $r
           size= $s
           sharedscripts
           postrotate
               /sbin/killall -HUP httpd
           endscript
       }
#####################apache_logs_$d###########################
_eof_

  else
echo -e "logrotate for this domian already exist"
        fi
else
echo -e " the domain does not exist "
fi
}

delete_log_rotation ()
{
read -p "Enter your domain name: " d
tmp=`echo $domain |sed s/\.com//g `

if [ -d /websites/"$d" ]; then

         if [  -n "$(sed -n
"/\#apache_logs_${d}\#/,/\#apache_logs_${d}\#/p" /etc/logrotate.conf)"
 ]; then

sed -i "/\#apache_logs_${d}\#/,/\#apache_logs_${d}\#/d" /etc/logrotate.conf

        else
echo -e "log rotate does not exist for this domain"
        fi
else
echo -e "The domain does not exist"
fi
}

edit_log_rotation ()
{
read -p "Enter your domain name: " d
read -p "Edit  the number of times you want logs to be rotated : " r
read -p "Edit  the size of your log sise " s
tmp=`echo $domain |sed s/\.com//g `


if [ -d /websites/"$d" ]; then

         if [  -n "$(sed -n
"/\#apache_logs_${d}\#/,/\#apache_logs_${d}\#/p" /etc/logrotate.conf)"
 ]; then

sed -i "/\#apache_logs_${d}\#/,/\#apache_logs_${d}\#/d" /etc/logrotate.conf

cat >> $config_file << _eof_
######################apache_logs_$d###########################
"/websites/$d/logs/$tmp.sys.qualiproj.access_log"
/websites/$d/logs/$tmp.sys.qualiproj.error_log {
           rotate $r
           size=$s
           sharedscripts
           postrotate
               /sbin/killall -HUP httpd
           endscript
       }
#####################apache_logs_$d###########################
_eof_
         else
echo -e "log rotate does not exist for this domain"
        fi
else
echo -e "The domain does not exist"
fi
}

read -p "Do you want to add, delete, or edit the logs rotation: " l

case $l in
add ) add_log_rotation
;;
delete ) delete_log_rotation
;;
edit ) edit_log_rotation
;;
* ) echo -e "Please type add delete or edit"
esac


done!!

-- 
सादर
अग्नेल्लो द्सौज़ा
www.linux-vashi.blogspot.com
www.bible-study-india.blogspot.com

Reply via email to