Solved

managing /var/apache/access_log  and error_log

Posted on 2006-07-03
9
308 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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 …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

770 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