You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Dror Braznitzki <Dr...@yellowpages.co.il> on 2002/03/13 10:02:14 UTC

Cleaning log files

Hello,

Is it safe to clean log files using 'cat /dev/null > log_file' while the
server is running ?
Is there a better way of doing it ?

Thanx,

Dror



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.yellowpages.co.il
**********************************************************************


Re: Cleaning log files

Posted by Artiom Morozov <ar...@phreaker.net>.
Imho it's not, however logs are not very well suitable for 
post-processing with analyzers, if rotated that way. Also restarting 
apache may not be good for very heavy loaded machine. So it all depends.

On 2002.03.13 11:36 RuneImp wrote:
> I use a croned shell script after all logs have been
> processed by PerlFect DailyStats.
> 
> All logs are place within this type of directory
> structure.
> 
> /usr/home/domainname.tld/web/logs/access.log
> /usr/home/domainname.tld/web/logs/error.log
> 
> This is the script:
> 
> #!/bin/sh
> for file in /usr/home/*/web/logs/*.log; do
>         echo Trimming $file
>         tail -5000 $file > temp
>         mv temp $file
> done
> /usr/local/sbin/apachectl graceful
> 
> 
> Is this a bad practice?
> 
> 
> -=- RuneImp
> ImpTech - Web Design, Hosting & Computer Tech
> http://imptech.net
> rune@imptech.net
> 
> 
> ----- Original Message -----
> From: "Artiom Morozov" <ar...@phreaker.net>
> To: <us...@httpd.apache.org>
> Sent: Wednesday, March 13, 2002 1:14 AM
> Subject: Re: Cleaning log files
> 
> 
> depends on how you're transferring logs to files, but in general -
> it's
> not. use logrotate(8) or rotatelogs from apache distribution.
> 
> On 2002.03.13 11:02 Dror Braznitzki wrote:
> > Hello,
> >
> > Is it safe to clean log files using 'cat /dev/null > log_file' while
> > the
> > server is running ?
> > Is there a better way of doing it ?
> >

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by RuneImp <ru...@imptech.net>.
I use a croned shell script after all logs have been
processed by PerlFect DailyStats.

All logs are place within this type of directory
structure.

/usr/home/domainname.tld/web/logs/access.log
/usr/home/domainname.tld/web/logs/error.log

This is the script:

#!/bin/sh
for file in /usr/home/*/web/logs/*.log; do
        echo Trimming $file
        tail -5000 $file > temp
        mv temp $file
done
/usr/local/sbin/apachectl graceful


Is this a bad practice?


-=- RuneImp
ImpTech - Web Design, Hosting & Computer Tech
http://imptech.net
rune@imptech.net


----- Original Message ----- 
From: "Artiom Morozov" <ar...@phreaker.net>
To: <us...@httpd.apache.org>
Sent: Wednesday, March 13, 2002 1:14 AM
Subject: Re: Cleaning log files


depends on how you're transferring logs to files, but in general - it's 
not. use logrotate(8) or rotatelogs from apache distribution.

On 2002.03.13 11:02 Dror Braznitzki wrote:
> Hello,
> 
> Is it safe to clean log files using 'cat /dev/null > log_file' while
> the
> server is running ?
> Is there a better way of doing it ?
> 
> Thanx,


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by Birl <sb...@astro.ocis.temple.edu>.
AM> Date: Wed, 13 Mar 2002 11:14:06 +0200
AM> From: Artiom Morozov <ar...@phreaker.net>
AM> Reply-To: users@httpd.apache.org
AM> To: users@httpd.apache.org
AM> Subject: Re: Cleaning log files
AM>
AM> depends on how you're transferring logs to files, but in general - it's
AM> not. use logrotate(8) or rotatelogs from apache distribution.
AM>
AM> On 2002.03.13 11:02 Dror Braznitzki wrote:
AM> > Hello,
AM> >
AM> > Is it safe to clean log files using 'cat /dev/null > log_file' while
AM> > the
AM> > server is running ?
AM> > Is there a better way of doing it ?
AM> >
AM> > Thanx,
AM>
AM> ---------------------------------------------------------------------



Another method I use, which was documented in earlier versions of Apache
(1.2.x) and may still be documented is:


# mv access_log access_log.old ;  kill -HUP `cat httpd.pid`



I guess the more "modern" way could be

# mv access_log access_log.old ;  apachectrl graceful



 Scott Birl      Scott.Birl@temple.edu
 UNIX Consultant/Systems Administrator   Computer  Services   Temple University
 1805 North Broad Street  Philadelphia   Pennsylvania 19122   United States
====*====*====*====*====*====*====*====+====*====*====*====*====*====*====*====*


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by Artiom Morozov <ar...@phreaker.net>.
depends on how you're transferring logs to files, but in general - it's 
not. use logrotate(8) or rotatelogs from apache distribution.

On 2002.03.13 11:02 Dror Braznitzki wrote:
> Hello,
> 
> Is it safe to clean log files using 'cat /dev/null > log_file' while
> the
> server is running ?
> Is there a better way of doing it ?
> 
> Thanx,

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by Stephen Reppucci <sg...@logsoft.com>.
You are correct, my statement that the file is unlinked is wrong
(funny how many times after you post something to a public list you
find a glaring error in your statements, huh? 8^), but I maintain
that 'cat'ing /dev/null to an open log file is *not* something that
should be relied upon, as I know it causes failures on some Unix
flavors. (If I remember correctly, this did not work on Solaris
2.6).

The 'mv' option *is* safe (safe == reliable), but the key point is
apache will continue to write to the 'mv'ed file until you tell it
to reopen its log files, thereby having it close the old file (which
now has a different name) and open a new log file with the original
name. Sending it a 'SIGUSR1' is the documented way of doing this.

<Steve>

On Wed, 13 Mar 2002, alex dyas wrote:

> 'cat /dev/null > log_file' does *not* unlink the file and does not cause
> the problems you've described (at least not under Solaris 2.7/2.8). I've
> been using this method for quite a while now quite sucessfully.
>
> The problems come when you try using mv to move the old apache log file
> away while apache is still running.  AFAIK apache's link to the log file
> is through its inode, not its name. Thus moving the file doesn't help.
>
> alex..
>
> Stephen Reppucci wrote:
> > Depends on how you define "safe", but I'd *not* use the method
> > you've illustrated here...
> >
> > Apache still has the original log file open, so even after doing the
> > 'cat', it'll still go along happily writing to the (now unlinked)
> > log file, and you'll lose those log records.  Depending upon whether
> > you're trying to preserve those logs (e.g., for traffic analysis)
> > this could be "a bad thing".  Regardless, the disk storage for the
> > logs won't be released until apache closes the log file.
> >
> > I've used logrotate before, but for a few large sites I maintained,
> > I was happier with a couple of custom shell scripts I hacked
> > together that (after 'grep'ing through the server configs to find
> > the log files) did the equivalent of:
> >
> >    mv access_log access_log.yyyyddmm.hhmmss
> >    apachectl graceful
> >
> > The 'graceful' sends a SIGUSR1 to the apache parent process, which
> > causes it to tell all of its children to close and reopen the log
> > file *after* completing any current transaction.  This technique has
> > always worked like a charm for me.
> >
> > Note that this is how it works under Unix, all bets are off as to
> > how the Win* OSes handle it...
> >
> > hth,
> > <Steve>
> >
> > On Wed, 13 Mar 2002, Dror Braznitzki wrote:
> >
> >
> >>Is it safe to clean log files using 'cat /dev/null > log_file' while the
> >>server is running ?
> >>Is there a better way of doing it ?
> >>
> >>Thanx,
> >>Dror
> >>
>
>
>

-- 
Steve Reppucci                                       sgr@logsoft.com |
Logical Choice Software                          http://logsoft.com/ |
=-=-=-=-=-=-=-=-=-=-  My God!  What have I done?  -=-=-=-=-=-=-=-=-=-=


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by alex dyas <ad...@twowaytv.co.uk>.
'cat /dev/null > log_file' does *not* unlink the file and does not cause 
the problems you've described (at least not under Solaris 2.7/2.8). I've 
been using this method for quite a while now quite sucessfully.

The problems come when you try using mv to move the old apache log file 
away while apache is still running.  AFAIK apache's link to the log file 
is through its inode, not its name. Thus moving the file doesn't help.

alex..

Stephen Reppucci wrote:
> Depends on how you define "safe", but I'd *not* use the method
> you've illustrated here...
> 
> Apache still has the original log file open, so even after doing the
> 'cat', it'll still go along happily writing to the (now unlinked)
> log file, and you'll lose those log records.  Depending upon whether
> you're trying to preserve those logs (e.g., for traffic analysis)
> this could be "a bad thing".  Regardless, the disk storage for the
> logs won't be released until apache closes the log file.
> 
> I've used logrotate before, but for a few large sites I maintained,
> I was happier with a couple of custom shell scripts I hacked
> together that (after 'grep'ing through the server configs to find
> the log files) did the equivalent of:
> 
>    mv access_log access_log.yyyyddmm.hhmmss
>    apachectl graceful
> 
> The 'graceful' sends a SIGUSR1 to the apache parent process, which
> causes it to tell all of its children to close and reopen the log
> file *after* completing any current transaction.  This technique has
> always worked like a charm for me.
> 
> Note that this is how it works under Unix, all bets are off as to
> how the Win* OSes handle it...
> 
> hth,
> <Steve>
> 
> On Wed, 13 Mar 2002, Dror Braznitzki wrote:
> 
> 
>>Is it safe to clean log files using 'cat /dev/null > log_file' while the
>>server is running ?
>>Is there a better way of doing it ?
>>
>>Thanx,
>>Dror
>>


-- 
-= alex dyas - webmaster - twowaytv - uk =-


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: Cleaning log files

Posted by Stephen Reppucci <sg...@logsoft.com>.
Depends on how you define "safe", but I'd *not* use the method
you've illustrated here...

Apache still has the original log file open, so even after doing the
'cat', it'll still go along happily writing to the (now unlinked)
log file, and you'll lose those log records.  Depending upon whether
you're trying to preserve those logs (e.g., for traffic analysis)
this could be "a bad thing".  Regardless, the disk storage for the
logs won't be released until apache closes the log file.

I've used logrotate before, but for a few large sites I maintained,
I was happier with a couple of custom shell scripts I hacked
together that (after 'grep'ing through the server configs to find
the log files) did the equivalent of:

   mv access_log access_log.yyyyddmm.hhmmss
   apachectl graceful

The 'graceful' sends a SIGUSR1 to the apache parent process, which
causes it to tell all of its children to close and reopen the log
file *after* completing any current transaction.  This technique has
always worked like a charm for me.

Note that this is how it works under Unix, all bets are off as to
how the Win* OSes handle it...

hth,
<Steve>

On Wed, 13 Mar 2002, Dror Braznitzki wrote:

> Is it safe to clean log files using 'cat /dev/null > log_file' while the
> server is running ?
> Is there a better way of doing it ?
>
> Thanx,
> Dror
-- 
Steve Reppucci                                       sgr@logsoft.com |
Logical Choice Software                          http://logsoft.com/ |
=-=-=-=-=-=-=-=-=-=-  My God!  What have I done?  -=-=-=-=-=-=-=-=-=-=


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org