Solved

Rotating log

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
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). …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

13 Experts available now in Live!

Get 1:1 Help Now