• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

managing /var/apache/access_log and error_log

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
mslibrarycommission
Asked:
mslibrarycommission
4 Solutions
 
yuzhCommented:
Or use cron to run a script to rotate the logs:

see my script in http:Q_21891238.html#16939051
0
 
TintinCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
yuzhCommented:
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
 
JohntuckCommented:
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
 
yuzhCommented:
We have given the working answers, split points?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now