apache log rotation script

#!/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

--

No comments:

Other Articles

Enter your email address: