#!/bin/ksh 

#############################################################################
##
## iMS monitoring and alarm script
##
## This script is part an example framework of what can be done.
## There are MANY ways that you can take this from here.
##
## File: $Rrotatelogs
##       A script to rotate the log files and keep a configured number around
##
#############################################################################

_CURR_WDIR=$(dirname $0)

COUNT=30

Usage()
{
    echo "$0 -l logfilename [-n numlogs]"
    exit 0
}

while [ $# -gt 0 ]
do
    case "$1" in
        -l)     shift; LOGFILE=$1;;
        -n)     shift; COUNT=$1;;

        -help)  Usage;;
    esac
    shift
done

## include definitions if necessary
if [ -z "$HEALTHMON_TMPDIR" ]
then
    . $_CURR_WDIR/../../etc/alarms.cfg
fi

if [ ! $LOGFILE ] ; then
        Usage
fi

CURDIR=`pwd`
if [ -d $reportlogdir ]; then
   cd $reportlogdir
   if [ -f $reportlogdir/$LOGFILE ]; then
      while [ $COUNT -gt 0 ]; do
        NEWEXT=$(($COUNT - 1))
        test -f $LOGFILE.$NEWEXT && mv $LOGFILE.$NEWEXT $LOGFILE.$COUNT
        COUNT=$(($COUNT -1))
      done
        test -f $LOGFILE && mv $LOGFILE $LOGFILE.$COUNT
   fi
   cd $CURDIR
   exit 0
else
  "echo $reportlogdir does not exist. Unable to roll logfiles"
   cd $CURDIR
   exit 1
fi

## end of script
