Solved

log files, especially apache lof files

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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 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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

743 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

14 Experts available now in Live!

Get 1:1 Help Now