Solved

managing /var/apache/access_log  and error_log

Posted on 2006-07-03
9
303 Views
Last Modified: 2013-12-27
My /var/apache/access_log and error_log are getting to big. I want to just keep the last 500 lines of each. Can I use the tail -500 comand and copy to another file and remove the original and rename the file witrh the last 500 lines to the original and can I do this while the system is running?
0
Comment
Question by:mslibrarycommission
9 Comments
 
LVL 10

Accepted Solution

by:
Nukfror earned 125 total points
ID: 17031582
0
 
LVL 38

Assisted Solution

by:yuzh
yuzh earned 125 total points
ID: 17034362
Or use cron to run a script to rotate the logs:

see my script in http:Q_21891238.html#16939051
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 125 total points
ID: 17039624
yuzh.

In your rotation script, I  would change

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

to

mv access_log access_log.${TODAY}
mv error_log error_log.${TODAY}

As mv is an atomic process and will be much quicker than copying the logs.  Additionally, if your logs are big and your freespace is low, you may run into space issues.

0
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.

 
LVL 38

Expert Comment

by:yuzh
ID: 17039693
Tintin,
     thanks for the suggestion, after "mv", you need to "re-create" the log files
and set the correct file permissions (use "touch + chmod").
0
 
LVL 1

Assisted Solution

by:Johntuck
Johntuck earned 125 total points
ID: 17194514
Easiest way to recreate those log files after a mv is: apachectl graceful

It'll recreate everything for you with the default permissions- much less room for script error :)

If you traffic is high enough, this could be done every 10-15 min.
0
 
LVL 38

Expert Comment

by:yuzh
ID: 17557557
We have given the working answers, split points?
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

Suggested Solutions

Title # Comments Views Activity
Font: I need Lato on my Mac 10 177
Where to get php 5.6 for AIX 7.1? 5 79
MarkLogic 1 68
Best way to split and output to csv in bash 2 60
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
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.

911 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

15 Experts available now in Live!

Get 1:1 Help Now