728x90
반응형
전에 포스팅 했던 날짜 기준으로 삭제하던 것을 수정해 보았습니다.
여기선 최신 파일 150개를 남겨 놓고 이전 파일들을 삭제 합니다.
여기선 최신 파일 150개를 남겨 놓고 이전 파일들을 삭제 합니다.
다음은 스크립트 내용이다.
- arcdel.sh ( AIX , HP , Linux 용)
#!/usr/bin/ksh
SHELLHOME=/fsudb/db2inst1/HOME/EXEM/SHELL/ARCDEL
NOW=`date '+%Y%m%d_%H%M'`
# Check Node Number And Make DIRNODE environment Variable
case `expr length $DB2NODE` in
1) DIRNODE=`expr NODE000$DB2NODE` ;;
2) DIRNODE=`expr NODE00$DB2NODE` ;;
3) DIRNODE=`expr NODE0$DB2NODE` ;;
4) DIRNODE=`expr NODE$DB2NODE`;;
esac
#echo $DIRNODE
# Connect to Database
db2 connect to $DBNAME >> /dev/null
# Get DB CFG ( archive log directory )
db2 get db cfg | grep LOGARCHMETH1 > $SHELLHOME/arc.out
# Get Archive log directory from out file
ARCHOME=`cat $SHELLHOME/arc.out | awk -F: '{print $2}'`
# Check last character from archive log directory
TEMP1=`expr length $ARCHOME`
TEMP2=`expr substr $ARCHOME $TEMP1 1`
#echo $TEMP2
# Make Full Archive log directory
if [ "$TEMP2" = "/" ] ; then
#ARCHOME=$ARCHOME$DB2INSTANCE/$DBNAME/$DIRNODE/C0000000
ARCHOME=$ARCHOME$DB2INSTANCE/$DBNAME/$DIRNODE
else
#ARCHOME=$ARCHOME/$DB2INSTANCE/$DBNAME/$DIRNODE/C0000000
ARCHOME=$ARCHOME/$DB2INSTANCE/$DBNAME/$DIRNODE
fi
# echo $ARCHOME
# Count archive log files
CNT=`find $ARCHOME -type f | wc -l`
DELCNT=`expr $CNT - 150`
DELCNT=`expr $CNT - 150`
#echo $CNT
#find $ARCHOME -mtime +2 -print
if [ $CNT -gt 150 ]
then
echo "Removing Files...." > $SHELLHOME/$NOW.out
find $ARCHOME -type f | xargs ls -t | grep -v dr >> $SHELLHOME/$NOW.out
sed -e '1,/150/d' $SHELLHOME/$NOW.out >> $SHELLHOME/$NOW_del.out
cat $SHELLHOME/$NOW_del.out | xargs /bin/rm
db2 terminate >> /dev/null
exit
find $ARCHOME -type f | xargs ls -t | grep -v dr >> $SHELLHOME/$NOW.out
sed -e '1,/150/d' $SHELLHOME/$NOW.out >> $SHELLHOME/$NOW_del.out
cat $SHELLHOME/$NOW_del.out | xargs /bin/rm
db2 terminate >> /dev/null
exit
fi
# Exit Shell
db2 terminate >> /dev/null
exit
- arcdel_sun.sh
#!/usr/bin/ksh
SHELLHOME=/fsudb/db2inst1/HOME/EXEM/SHELL/ARCDEL
NOW=`date '+%Y%m%d_%H%M'`
# Check Node Number And Make DIRNODE environment Variable
case `/usr/ucb/expr length $DB2NODE` in
1) DIRNODE=`/usr/ucb/expr NODE000$DB2NODE` ;;
2) DIRNODE=`/usr/ucb/expr NODE00$DB2NODE` ;;
3) DIRNODE=`/usr/ucb/expr NODE0$DB2NODE` ;;
4) DIRNODE=`/usr/ucb/expr NODE$DB2NODE`;;
esac
#echo $DIRNODE
# Connect to Database
db2 connect to $DBNAME >> /dev/null
# Get DB CFG ( archive log directory )
db2 get db cfg | grep LOGARCHMETH1 > $SHELLHOME/arc.out
# Get Archive log directory from out file
ARCHOME=`cat $SHELLHOME/arc.out | awk -F: '{print $2}'`
# Check last character from archive log directory
TEMP1=`/usr/ucb/expr length $ARCHOME`
TEMP2=`/usr/ucb/expr substr $ARCHOME $TEMP1 1`
#echo $TEMP2
# Make Full Archive log directory
if [ "$TEMP2" = "/" ] ; then
#ARCHOME=$ARCHOME$DB2INSTANCE/$DBNAME/$DIRNODE/C0000000
ARCHOME=$ARCHOME$DB2INSTANCE/$DBNAME/$DIRNODE
else
#ARCHOME=$ARCHOME/$DB2INSTANCE/$DBNAME/$DIRNODE/C0000000
ARCHOME=$ARCHOME/$DB2INSTANCE/$DBNAME/$DIRNODE
fi
#echo $ARCHOME
# Count archive log files
CNT=`find $ARCHOME -type f | wc -l`
DELCNT=`expr $CNT - 150`
DELCNT=`expr $CNT - 150`
if [ $CNT -gt 150 ]
then
echo "Removing Files...." > $SHELLHOME/$NOW.out
find $ARCHOME -type f | xargs ls -t | grep -v dr >> $SHELLHOME/$NOW.out
sed -e '1,/150/d' $SHELLHOME/$NOW.out >> $SHELLHOME/$NOW_del.out
cat $SHELLHOME/$NOW_del.out | xargs /bin/rm
db2 terminate >> /dev/null
exit
fi
find $ARCHOME -type f | xargs ls -t | grep -v dr >> $SHELLHOME/$NOW.out
sed -e '1,/150/d' $SHELLHOME/$NOW.out >> $SHELLHOME/$NOW_del.out
cat $SHELLHOME/$NOW_del.out | xargs /bin/rm
db2 terminate >> /dev/null
exit
fi
# Exit Shell
exit
반응형