Solved

Rotating log

Posted on 2003-10-28
2
621 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
[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
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intel fortran compiler (ifort) 5 81
Unix Help with:  mailx -s 17 65
how to write and save a unix script 12 36
cmake and message 1 21
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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