Solved

Rotating log

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
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.

726 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