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
Solved

log files, especially apache lof files

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
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.

828 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