Solved

log files, especially apache lof files

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

816 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

12 Experts available now in Live!

Get 1:1 Help Now