Solved

Rotating log

Posted on 2003-10-28
2
615 Views
Last Modified: 2010-04-20
Hi,

I have a log file "apache.log" in /home/www/mysites.com/logs/

So, the full path is /home/www/mysites.com/logs/apache.log

Anyone can tell me how to do "log rotate" with that log? like in the /var/log , I saw messages.1 messages.2 etc.

Please teach me with step-by-step instruction :)

Thank you so much.
0
Comment
Question by:nova2002
2 Comments
 
LVL 9

Expert Comment

by:majorwoo
ID: 9637363
it depends on how many back you want to keep, but you could make a simpel script, and call it from cron

something like




#!/bin/bash

#just for goot practice, in case you move it
DIR="/home/www/mysites.com/logs/"

#go there
cd $DIR

#mv and old ones back, this will keep the last weeks logs...
if [ -f apache.log5 ]; then
  mv apache.log5 apache.log6
fi
if [ -f apache.log4 ]; then
  mv apache.log4 apache.log5
fi
if [ -f apache.log3 ]; then
  mv apache.log3 apache.log4
fi
if [ -f apache.log2 ]; then
  mv apache.log2 apache.log1
fi
if [ -f apache.log1 ]; then
  mv apache.log1 apache.log2
fi

#now move the actual one back...
if [ -f apache.log ]; then
  cp apache.log apache.log1 && echo "" > apache.log
fi

#all done
exit 0






then just put that in cron to run at some obscure time..
edit /etc.crontab and sadd something like

# log rotate
00 4 * * * root /path/to/script/logrotate.sh







0
 
LVL 20

Accepted Solution

by:
Gns earned 35 total points
ID: 9644174
If you have the logrotate package loaded on your system, you could just add an entry to /etc/logrotate.conf, add it to the (probably existing) file /etc/logrotate.d/apache, or add a completely new file in /etc/logrotate.d ... The format is quite lucid... Look at other files there, and read
man logrotate
Note that you might have o do something to make apache close the old logfile, and open the new one. Something like

/var/log/httpd/access_log /var/log/httpd/error_log /var/log/httpd/agent_log /var
/log/httpd/referer_log /var/log/httpd/apache_runtime_status
/var/log/httpd/ssl_mutex /var/log/httpd/ssl_access_log /var/log/httpd/ssl_error_
log /var/log/httpd/ssl_agent_log /var/log/httpd/ssl_request_log
/var/log/httpd/suexec_log
{
    rotate 5
    monthly
    missingok
    nocompress
    prerotate
        ADVXctl closelogs
    endscript
    postrotate
        ADVXctl closelogs
    endscript
}
could be correct for a mandrake 9.1 with the Advance Xtranet server. Or something a lot simpler, like

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
    endscript
}
which is for a RH9s httpd... In the above examples, one could just add the filename(s) you want rotated.
But do read the manpage... If you have it:-).

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

932 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

18 Experts available now in Live!

Get 1:1 Help Now