?
Solved

managing /var/apache/access_log  and error_log

Posted on 2006-07-03
9
Medium Priority
?
318 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
[X]
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
9 Comments
 
LVL 10

Accepted Solution

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

Assisted Solution

by:yuzh
yuzh earned 500 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
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.
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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