Solved

log files, especially apache lof files

Posted on 2006-06-19
3
332 Views
Last Modified: 2013-12-27
Hi,

my log files of apache( error_log file and access_log file) have increased too much in size and i want to gzip them. Do i just gzip them and apache will create the same files itself or do I have to create an empty files after gunzip.

Regards
0
Comment
Question by:naufal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:arthurjb
ID: 16937677
You should not work on the files while apache (or any other process) has the file open.

The safest way if you cannot or do not want to shut the process down, is to copy the file to another file, and then gzip the copy.

then make the original file 0 size by typing "> error.log"

The problem is that if you do not have any space available to copy the file to, then you will have a problem...
0
 

Author Comment

by:naufal
ID: 16937843
How can we know if any process has the file open?
0
 
LVL 38

Accepted Solution

by:
yuzh earned 50 total points
ID: 16939051
You can use script to rotate the log and run the script as a cron job, here's
a script can do the job for you. (PS: my script use GNU tar, if you don have
you can download GNU tar from
         http://sunfreeware.com/
         otherwise, you can use "tar" and "gzip" to do the job. please modify the
         script to suite your need.

#!/bin/ksh
#=================================================
# Script Name: soem-web-log
#
# This script rotate the soem webserver logs, use cron to run it once
# every 4 months
# Jan 15, May 15, Sep 15
# crontab record
# 5 0 15 1,5,9 * /root/bin/soem-web-log >/dev/null 2>&1

#
# To verify *.tar.gz file: /usr/local/bin/tar -ztvf filname.tar.gz
# To extract *.tar.gz file: /usr/local/bin/tar -xtvf filname.tar.gz

LOGDIR=/var/apache/logs
TODAY=`date +%d%m%Y`

# Stop apache befor rotate the logs
cd $LOGDIR
/etc/rc3.d/S50apache stop

cp -p access_log access_log.${TODAY}
cp -p error_log error_log.${TODAY}
cat /dev/null > access_log
cat /dev/null > error_log

# Restart apache
/etc/rc3.d/S50apache start

#clean up
/usr/local/bin/tar -czf Logs_${TODAY}.tar.gz *log.${TODAY}
rm *log.${TODAY}

exit

# End of script
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question