Solved

Rotating log

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

756 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