1834571 Members
3170 Online
110069 Solutions
New Discussion

log house keeping

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

log house keeping

Hi,

I am performing log house keeping and want to keep all entries after the first of April ...

how can I cat out all information from April?

the log is appended everytime something is writing and has the time stamp at the begining of the entry.

I was just wondering is there a specific command that can do this?

thanks

Chris.
hello
9 REPLIES 9
Steven E. Protter
Exalted Contributor
Solution

Re: log house keeping

Shalom,

I would use logrotate to copy the logs to a new location the first of every month.

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/logrotate-2.5/

The code here is a little old and may need adjustment. I recall a thread that said in order to get this to work on HP-UX you may need to compile the code.

Logrotate, a standard par to of Linux is worth the effort to install, because its so helpful.

Alternate:
scripts that back up the log file and then > logfile name, run by cron the first of the month.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
OFC_EDM
Respected Contributor

Re: log house keeping

Or just script it.
Then add it to cron

#!/usr/bin/ksh
#Use cron to schedule on the 1st of every month

typeset -i i=1

mv ./log1 ./log2
mv ./log2 ./log3
mv ./log3 ./log4
mv ./log4 ./log5
mv ./log5 ./log6
cp ./newlog ./log1
echo "Starting new log" > ./newlog

Customize to suit your needs.

Don't move syslog as you'll break the daemon.
Redirect to it as I did with newlog above.
The Devil is in the detail.
lawrenzo_1
Super Advisor

Re: log house keeping

thanks for the suggestions and I can rotate a log etc in this method however I am interested in a one off task .....

ie I find a logfile that is xxx days old and I want to keep say 60 days of data and I cannot shut down the app so the logfile remains active but is written to every 20 minutes or so.

Chris.

hello
Dennis Handly
Acclaimed Contributor

Re: log house keeping

>I find a logfile that is xxx days old and I want to keep say 60 days of data and I cannot shut down the app so the logfile remains active but is written to every 20 minutes or so.

If the logfile is kept open, there is not much you can do if the app is continually writing to the end of the file.
Yogeeraj_1
Honored Contributor

Re: log house keeping

hi Chris,

at the risk of losing some log information, you can also implement the following command:

cp -p ;cat /dev/null >

e.g.

cp -p mylog.log mylog.log.$(date +%y%m%d-%H%M); cat /dev/null > mylog.log


hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: log house keeping

hi again chris,

you may also schedule this using the CRON.

e.g.

#*******************************************************************************
# min|hour |day |month|day |script
# | |of mo| |of wk|
#----|-----|-----|-----|-----|--------------------------------------------------
#*******************************************************************************
#
#****
# Log maintenance Every 2 months
#****
00 05 30 1,3,5,7,9,11 * cp -p mylog.log mylog.log.$(date +\%y\%m\%d-\%H\%M); cat /dev/null > mylog.log
#*******************************************************************************
# END OF TABLE day0->Sunday day6->Saturday
#*******************************************************************************

(you will to implement the cleanup scripts accordingly - so that the archived logfiles are purged at the desired interval)

hope this helps too!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
VK2COT
Honored Contributor

Re: log house keeping

Hello,

Other replies already covered some methods
to help with log file rotation.

May I add some more, not necessarily
direclty written for HP-UX but quite
portable and should help:

a) HP-UX Porting site has another one
(albeit a bit old too):

http://gatekeep.cs.utah.edu/hppd/hpux/Sysadmin/smartlog-3.5/

At least, both smartlog and logrotate
come with the sources...

b) Scripts based on Perl modules like
Logfile-Rotate

c) Replace standard syslog daemon with
syslog-ng

d) Bill Hassell (our very knowledgeable
colleague and long-term ITRC member)
has logtrim:

http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1053445&admit=109447627+1209468059756+28353475

e) An example based on Sun's generic Shell
script that you can modify to suit your
needs, or at least learn from it:

#!/bin/sh
#
# Copyright(c) 1997, by Sun Microsystems, Inc.
#
LOG=messages
cd /var/adm
test -f $LOG.2 && mv $LOG.2 $LOG.3
test -f $LOG.1 && mv $LOG.1 $LOG.2
test -f $LOG.0 && mv $LOG.0 $LOG.1
mv $LOG $LOG.0
cp /dev/null $LOG
chmod 644 $LOG
#
LOGDIR=/var/adm
LOG=syslog
if test -d $LOGDIR
then
cd $LOGDIR
if test -s $LOG
then
test -f $LOG.6 && mv $LOG.6 $LOG.7
test -f $LOG.5 && mv $LOG.5 $LOG.6
test -f $LOG.4 && mv $LOG.4 $LOG.5
test -f $LOG.3 && mv $LOG.3 $LOG.4
test -f $LOG.2 && mv $LOG.2 $LOG.3
test -f $LOG.1 && mv $LOG.1 $LOG.2
test -f $LOG.0 && mv $LOG.0 $LOG.1
mv $LOG $LOG.0
cp /dev/null $LOG
chmod 644 $LOG
sleep 40
fi
fi
#
kill -HUP `cat /etc/syslog.pid`

f) Many Shell scripts, like:

http://www.zazzybob.com/bin/logrevolver.sh.html

g) There is also a BASH script called
logrotate:

http://iain.cx/src/logrotate/

h) Freshmeat project newsyslog:

http://freshmeat.net/projects/newsyslog/

A bit of creativity goes a log way :)

I hope this helps a bit...

Cheers,

VK2COT
VK2COT - Dusan Baljevic
John Tartt
New Member

Re: log house keeping

This is what I use on HPUX11i:

DATE=`date +%m%d%y`
ARCH=

# Roll over syslog.log
#
cd /var/adm/syslog
umask 022
cp syslog.log log.last
cp /dev/null syslog.log
/bin/kill -HUP `/bin/cat /var/run/syslog.pid`
uniq log.last $ARCH/syslog.${DATE}
rm log.last
#

NOTE: This way I can search all log files for a given month using one grep command. Since the month is the first two digits all I have to do is grep on syslog.04???? for all of Aprils syslog files.

John
lawrenzo_1
Super Advisor

Re: log house keeping

thanks all for the input
hello