Korn Shell实现文件大小比较

#!/usr/bin/ksh
# check pkg size
# if the size is 5% greater than predecessor, then print warning message
# else print the pkg size
#set -x

filesize()
{
	pkg=$1
	echo `du -k $pkg|tail -1|cut -f 1`
}

compare_pkgsize()
{
	pkg1=$1
	pkg2=$2
	percentage=$3||5
	pkg1_size=`filesize $pkg1`
	pkg2_size=`filesize $pkg2`
	gt_percent $pkg1_size $pkg2_size $percentage
}

compare_label_pkgsize()
{
	label1=$1
	label2=$2
	percentage=$3||5
	nightly_build_dir=$4||'/mot/proj/wibb_bts/daily/'
	label1_size=`filesize $nightly_build_dir/$label1`
	label2_size=`filesize $nightly_build_dir/$label2`
	gt_percent $label1_size $label2_size $percentage
}

gt_percent()
{
	size1=$1
	size2=$2
	percentage=$3
	inc_size=`echo "$size1-$size2" | bc`
	inc_by_percent=`echo "scale=2;$size2*(1+$percentage/100)" | bc`
	#echo "increase size: $inc_size, increse by percent: $inc_by_percent"
	is_ge=`echo "$size1 $inc_by_percent" | awk '{printf "%d",$1-$2}'`
	#echo "is greater than: $is_ge"
	if [ $is_ge -ge 0 ]; then
		echo "$size1 kb, predecessor $size2 kb, file size incresed $percentage percent than predecessor!"
	else
		echo "$size1 kb"
	fi
}

if [ $# -lt 2 ]; then
	echo '''
	Usage:
		cksize file1 file2 [percentage]
	'''
	exit 1
fi
#the comparation should depends on 2 files existing
if [ -e "$1" ] && [ -e "$2" ]; then
	if [ -n "$3" ]; then
		percentage=$3
		#echo "percentage: $percentage"
	else
		percentage=5
	fi
	compare_pkgsize $1 $2 $percentage
else
	echo "`filesize $1` kb"
fi

你可能感兴趣的:(F#)