Monday, October 26, 2009

remove outdated files based on minor build number

I've created a script to remove old installation file based on the minor build number.
In one project I'm working on, we need to keep the file with the largest build number. Here's a sample to check which build number is the latest one.

for file in `find . -name \*$ESBPREFIX\*.isvp`
do
# echo $file
NAMELENGTH=`expr length $file`
POSITION=`expr $NAMELENGTH - 7`
ESBVERSION=`expr substr $file $POSITION 3`
if [ `expr index $ESBVERSION "."` -eq 1 ]; then
ESBVERSION=`expr substr $ESBVERSION 2 2`
fi
if [ `expr index $ESBVERSION "."` -eq 2 ]; then
ESBVERSION=`expr substr $ESBVERSION 3 1`
fi
# echo "[CO Build Number: $ESBVERSION]"
if [ $ESBVERSION -gt $MAXESBBDNR ]; then
MAXESBBDNR=$ESBVERSION
fi
done

No comments: