#! /bin/sh
#
# ident "@(#)newcleventlog 1.3 03/10/17 SMI"
#
# Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# newcleventlog - cluster event log rotator.
#
#  This program is typically run by cron to age/archive
#  cluster event logs. Upto eight log versions are kept on each
#  cluster node at any given time.
#

file_rotation()
{
    is_a_real_file=`echo $1 | awk '/\.[0-9]*$/ { print "0"; exit 0 } { print "1" }'`

    if test -f $1 && test "$is_a_real_file" = "1"
    then
	test -f $1.7 && rm $1.7
	test -f $1.6 && mv $1.6  $1.7
	test -f $1.5 && mv $1.5  $1.6
	test -f $1.4 && mv $1.4  $1.5
	test -f $1.3 && mv $1.3  $1.4
	test -f $1.2 && mv $1.2  $1.3
	test -f $1.1 && mv $1.1  $1.2
	test -f $1.0 && mv $1.0  $1.1
	if test -s $1
	then
	    mv $1 $1.0
	fi
	cp /dev/null $1
	chmod 644 $1
    fi
}

# The following routine is for directories only

dir_rotation()
{
    cd $1
    for file in `ls`
    do
	general_rotation $file
    done
    cd ..
}

# The following routine is for both directories and files

general_rotation()
{
    if test -d $1
    then
	dir_rotation $1
    fi

    if test -f $1
    then
	file_rotation $1
    fi
}

general_rotation $1
sleep 40
pkill -HUP cl_eventlogd
