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 :


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 ];
                     cd $YEAR
                          if [ -a 0$MONTH ];
                                  tar -zcvf 0$MONTH.tar.gz 0$MONTH
                                  rm -rf /var/www/$f/log/$YEAR/0$MONTH

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

05 03 1 * * sh /root/
Share this page:

5 Comment(s)

Add comment


From: at: 2008-06-12 13:25:24

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.

From: at: 2008-06-12 15:57:07

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:



From: at: 2008-06-13 05:48:20

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

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

any clue ?

From: at: 2008-06-17 01:19:31

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

cd test &>/dev/null



From: at: 2008-11-24 11:57:58


 It's good but with one problem:

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