#!/bin/bash

# this script is used to kick off the unwanted dumps, meaning if the total number
# of dump in each type is more than the specified allowable number, then delete
# the old dump files using timestamp


# arg 1 is dump type with serial number, SYSDUMP.10000546 or FSPDUMP.10000546
# arg 2 is allowable number , 4

usage()
{
   echo Usage : clearDumpDir -dumptype  -number
   echo "                     -dumptype with serial number  SYSDUMP.1000546 or FSPDUMP.10000546"
   echo "                     -number    4"
   exit 0
}


if [ "$1" == "" ]
then
   usage
fi 

if [ "$2" == "" ]
then
   usage
fi



cd /dump
k=0


files=`ls | grep -cwF $1`
#echo $files
if [ $files -gt $2 ]
then 
    for i in `ls -tx $1.*`
    do
      #echo getting $i
      k=`expr $k + 1`
      if [  $k -gt $2  ]
      then
        #echo removing $i 
        rm -rf $i
      fi
    done
fi
