#!/bin/sh
# 
# @DEC_COPYRIGHT@
#
# HISTORY
# $Log: misclog_cleanup.sh,v $
# Revision 1.1.1.1  2003/12/11 15:40:53  ajay
# Importing Evm sources.
#
# Revision 1.1.1.1  2002/09/12 15:43:59  lsn
# EVM source - Linux initial version
#
# Revision 1.1.11.1  2001/09/26  18:58:39  Anthony_Hoffman
# 	redo of wildcatos submits
#
# Revision 1.1.9.1  2001/07/30  18:08:37  Anthony_Hoffman
# 	wc.evm.002.portability
#
# Revision 1.1.7.1  1999/12/15  18:33:42  Peter_Wolfe
# 	Fix for qar 75505. /var/adm/sysman is now a directory
# 	and the smsd logs are now in a sysman_station/logs
# 	like they always should have been
#
# Revision 1.1.5.3  1999/03/30  21:40:18  Jem_Treadwell
# 	Final drop for BL23 from EVM shared sandbox
# 	[1999/03/29  21:31:22  Jem_Treadwell]
#
# Revision 1.1.2.3  1999/03/29  20:03:59  Jem_Treadwell
# 	QAR 69538: Added smsd message file to misclog channel's retrieval and
# 	cleanup functions.
# 	[1999/03/29  20:02:39  Jem_Treadwell]
# 
# Revision 1.1.2.2  1999/03/25  17:24:16  Jem_Treadwell
# 	Initial submit - empty file
# 	[1999/03/25  17:23:48  Jem_Treadwell]
# 
# $EndLog$
# 
# @(#)$RCSfile: misclog_cleanup.sh,v $ $Revision: 1.1.1.1 $ (DEC) $Date: 2003/12/11 15:40:53 $
# 

# This script handles the misclog event channel daily cleanup.

. /usr/sbin/evmcommandset

#===================================================================
# Function: smsd message file cleanup
#
# This function archives and deletes smsd message files.
# Message files which are older than the archive period are zipped.
# Message files and archives which are older than the expire
# period are deleted.
#===================================================================
cleanup_smsd_logs()
{
    LOGDIR=/var/adm/sysman/sysman_station/logs
    ARCHIVE_SUFFIX='\.gz'

    # Switch off filename expansion:
    set -f

    LOG_PATTERN='smsd_[12][-_:0-9]*.log_[0-9][0-9][0-9]'
    ARCHIVE_PATTERN=${LOG_PATTERN}${ARCHIVE_SUFFIX}

    if [ -d $LOGDIR -a -x $LOGDIR ]
    then

	HERE=`pwd`
	cd $LOGDIR

	# If the archive period is non-zero we'll archive any aged logfiles.
	# If the archive period is zero and the expire period is non-zero,
	# we'll delete any logfiles which are older than the expire period.
	if [ $ARCHIVE_DAYS != 0 ]
	then
	    # Compress all logfiles which are older than the archive period:
	    eval ${FIND} . -type f -name $LOG_PATTERN -mtime +$ARCHIVE_DAYS |
		${XARGS} ${GZIP} -N
	else
	    if [ $EXPIRE_DAYS != 0 ]
	    then
		# Delete all logfiles which are older than the expire period:
		eval ${FIND} . -type f -name $LOG_PATTERN -mtime +$EXPIRE_DAYS |
		    ${XARGS} $RM
	    fi
	fi

	# If the expire period is non-zero, we'll delete any archived
	# files which are older than the expire period.
	if [ $EXPIRE_DAYS != 0 ]
	then
	    # Delete all archived files which are older than the delete period:
	    eval ${FIND} . -type f -name $ARCHIVE_PATTERN -mtime +$EXPIRE_DAYS |
		${XARGS} $RM
	fi
	cd $HERE
    fi
    set +f
}

ARCHIVE_DAYS=7
EXPIRE_DAYS=31

if [ "$1" != "" ]
then
    ARCHIVE_DAYS=$1
fi

if [ "$2" != "" ]
then
    EXPIRE_DAYS=$2
fi

cleanup_smsd_logs

exit 0
