Solved

log files, especially apache lof files

Posted on 2006-06-19
3
310 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now