Operating System - HP-UX
1833405 Members
3067 Online
110052 Solutions
New Discussion

Creating Multiple syslog.log Versions

 
SOLVED
Go to solution
Yosef Rosenblatt
Frequent Advisor

Creating Multiple syslog.log Versions

I need to retain more than one previous version of syslog.log. I don???t know the mechanism by which syslog.log is copied/renamed/moved to OLDsyslog.log but it would not matter to me if OLDsyslog is copied/renamed/moved to a new file or the original syslog.log is copied/renamed/moved to a new file. Is there a way this can be done.

Thanks,
Yosef Rosenblatt
9 REPLIES 9
harry d brown jr
Honored Contributor

Re: Creating Multiple syslog.log Versions

harry d brown jr
Honored Contributor

Re: Creating Multiple syslog.log Versions

Here's a sample script I found:

#!/bin/sh
#
# Roll over the syslogd log files
#

PATH=/bin:/usr/bin

SYSLOGCONF=/etc/syslog.conf
PIDFILE=/var/run/syslogd.pid
OLDDIR=/var/log/.oldlogs
LIM_SIZE=300

main()
{
echo "Rotating syslog log files:"

LOGFILES=`sed -n '
/^#/d
/^$/d
s/[^ ]*[ ]*\(\/.*\)/\1/p' < $SYSLOGCONF | sort | uniq | egrep -v '^(/dev/|@)'`

for FILE in ${LOGFILES}
{
if [ -f $FILE ]; then
eachfile $FILE
fi
}

echo sending SIGHUP to syslogd
kill -1 `cat $PIDFILE`
}

eachfile()
{
size=`sum $1 | awk '{print $2}'`
if [ $size -ge $LIM_SIZE ]; then
echo "Rotating $1 file."
roll5 $1
fi
}

roll()
{
if [ -f "$1" ]; then
mv "$1" "$2"
fi
}

roll5()
{
TAIL=`echo $1 | sed 's/.*\///'`
OLDLOG="${OLDDIR}/${TAIL}"

roll "$OLDLOG".4 "$OLDLOG".5
roll "$OLDLOG".3 "$OLDLOG".4
roll "$OLDLOG".2 "$OLDLOG".3
roll "$OLDLOG".1 "$OLDLOG".2
roll "$1" "$OLDLOG".1
cp /dev/null $1
chmod 644 $1
}

main ${1+"$@"}
exit 0


live free or die
harry
Live Free or Die
Pete Randall
Outstanding Contributor

Re: Creating Multiple syslog.log Versions

Christopher McCray_1
Honored Contributor

Re: Creating Multiple syslog.log Versions

Hello,

First thing is to make a backup copy of the /sbin/init.d/syslogd file to syslogd.bak.

edit the syslogd file and change where the syslog.log file is moved to OLDsyslog.log to change it to syslog.log with the date appended to it:

if [ -x /usr/sbin/syslogd -a -f /etc/syslog.conf ]; then
if [ -f /var/adm/syslog/syslog.log ]; then
mv /var/adm/syslog/syslog.log /var/adm/syslog/syslog.log.$(date
+%Y%m%d).$(date +%H%M%S)

Hope this helps

Chris
It wasn't me!!!!
Yosef Rosenblatt
Frequent Advisor

Re: Creating Multiple syslog.log Versions

Thanks to all that answered. I did not make a very important point clear. I run a diagnostic program that among other things panics my system peoridically. This may happen at any time of the day and may occur a few times an hour. What I need is a mechanism by which either syslog is copied to a file other than OLDsyslog and the name incremented or that OLDsyslog is copied to a new file before every shutdown.

Again thanks,
Yosef
Yosef Rosenblatt
Frequent Advisor

Re: Creating Multiple syslog.log Versions

Sorry I forgot to add to the last statement:

For this reason I need something that is not a manual process but is built into the way the o/s handles its shutdown procedures.

Thanks,
yosef
Christopher McCray_1
Honored Contributor
Solution

Re: Creating Multiple syslog.log Versions

Then I don't understand, Yosef, because what I had proposed you do is use the existing statup script.

Every time your system panics and subsequently comes up and starts up syslogd, instead of renaming syslog.log to OLDsyslog.log, it renames it with a unique date/timestamed syslog.log

Hope this clears up my previous post.

Chris
It wasn't me!!!!
harry d brown jr
Honored Contributor

Re: Creating Multiple syslog.log Versions

You could send your syslog entries to a syslog server, or put a call to that script I gave you in a new shutdown script.

live free or die
harry
Live Free or Die
Yosef Rosenblatt
Frequent Advisor

Re: Creating Multiple syslog.log Versions

Chris,
I wrote my second question before i read your answer. I just tested it and it works perfectly. Thanks a lot.

Yosef