How To Reduce Log File Disk Usage With ISPConfig Or LAMP

Want to support HowtoForge? Become a subscriber!
 
Submitted by marchost (Contact Author) (Forums) on Thu, 2008-06-12 13:06. :: ISPConfig | Linux | Control Panels

How To Reduce Log File Disk Usage With ISPConfig Or LAMP

Slowly I was seeing my disk usage increasing, I knew it was log files that were getting bigger and bigger. I found out that Apache log files were the worst, there was around 1GB of space used in 3 months.

So I decided to make a bash script that would compress Apache log file every month.

I run ISPConfig, the script can be modified to your needs :

#!/bin/bash

MONTH="$((`date +%m`-1))"
YEAR=$(date +"%Y")

cd /var/www/

for f in $(ls /var/www | grep web); do
             cd /var/www/$f/log
             if [ -a $YEAR ];
             then
                     cd $YEAR
                          if [ -a 0$MONTH ];
                          then
                                  tar -zcvf 0$MONTH.tar.gz 0$MONTH
                                  rm -rf /var/www/$f/log/$YEAR/0$MONTH
                          fi
             fi
done

Then you run this script in your crontab the first day of each month:

05 03 1 * * sh /root/logclean.sh

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by LukaszP (registered user) on Mon, 2008-11-24 12:57.

Hi!

 It's good but with one problem:

 line 3: 'date +%m'-1: syntax error: operand expected (error token is "'date +%m'-1")

Submitted by mumbly (registered user) on Fri, 2008-06-13 06:48.

On an ISPConfig Ubuntu Hardy system "Perfect server setup" :

sh /root/logclean.sh
/root/logclean.sh: line 9: cd: /var/www/webalizer/log: No such file or directory

any clue ?

Submitted by marchost (registered user) on Tue, 2008-06-17 02:19.

Hi, just add &>/dev/null in front of cd, tar and rm command such as :

cd test &>/dev/null

Marc

 

Submitted by rehren (registered user) on Thu, 2008-06-12 16:57.

nice script - but there is already in existence a very nice log rotating utility which should be obtainable on most any unix os - 'logwatch' - here's a nice article about it:

http://www.debian-administration.org/articles/117

 

 

Submitted by zloeber (registered user) on Thu, 2008-06-12 14:25.
How is this a step above or beyond configuring logrotate correctly? Logrotate is part of almost any default install and you can easily fine grain what gets rotated and when with the conf file in etc.