呵呵,这个脚本的默认统版目录为偶们四川的=/usr/scabs,回车默认统计901机构为偶这里的511111901,统计日期为昨日。终端打印统计结果的函数prin()暂时未用,打算更改为自定义或打印结果的兄弟请自行动手哈。。想改就改。^_^
#!/bin/ksh
#查询网点余额的shell V051025
#乐山市沙湾区邮政局 宋 涛
trap "tput sgr0 ; echo ; rm ~/yetj.txt 2>/dev/null; exit " 0 1 2 3 9 15
prin() #终端打印函数 #暂时未用
{
echo ""
cat $1 > $(tty)
echo ""
}
data()
{
month=$(date +%m)
day=$(date +%d)
year=$(date +%Y)
day=$(expr $day - 1)
if [ $day -eq 0 ]; then
month=$(expr $month - 1)
if [ $month -eq 0 ]; then
month=12
day=31
year=$(expr $year - 1)
else
month=$(printf "%02d" $month)
case $month in
01|03|05|07|08|10|12) day=31;;
04|06|09|11) day=30;;
02)
if [ $(expr $year % 4) -eq 0 ]; then
if [ $(expr $year % 400) -eq 0 ]; then
day=29
elif [ $(expr $year % 100) -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
test $(expr length $day) -eq 1 && day=$(printf "%01d"$day)
day=${month}$day
}
inputfdindir()
{
while :
do
clear
echo "\n\t\t余 额 查 询 表\n\n"
[ "$finddir" ] && echo "\n请输入欲统计余额的县级901机构号(回车默认为沙湾局): ${finddir}" \
|| read finddir?"请输入欲统计余额的县级901机构号(回车默认为沙湾局): "
[ "$finddir" ] || { finddir="511111901" ; break ; }
case $finddir in
q|Q) exit 0 ;;
sw) finddir="511111901" ; break ;;
esac
test $(expr length $finddir) -ne 9 && { echo "\n机构号长度错误!\n" ; read tmp ; finddir= ; continue ; }
test $(expr $finddir : "^[0-9][0-9]*$") -gt 0 || { echo "\n机构号输入错误!\n" ; read tmp ; finddir= ; continue ; }
test -d ${scabsdir}/print/$finddir && break || { echo "\n无此机构号!\n" ; read tmp ; finddir= ; continue ; }
done
}
inputday()
{
while :
do
echo "\n"
[ "$day" ] || read day?"请输入欲统计余额的日期(回车默认为昨日): "
[ "$day" ] || { data ; break ; }
[ "$day" = "q" -o "$day" = "Q" ] && exit 0
[ "$day" = "yesterday" ] && { data ; break ; }
test $(expr length $day) -ne 4 && { echo "\n日期长度错误!\n" ; read tmp ; day= ; continue ; }
test $(expr $day : "^[0-9][0-9]*$") -gt 0 && break || { echo "\n日期输入错误!\n" ; read tmp ; day= ; continue ; }
done
}
tput bold
scabsdir=/usr/scabs #四川统版目录
finddir=$1 #县级901机构号
day=$2 #统计日期
inputfdindir $finddir
inputday $day
for name in $(find ${scabsdir}/print/$finddir -name "rpt_acc_bal_001*${day}.dat")
do
[ -r $name ] || { echo "\n ${name} 文件不可读\n" ; read ; continue ; }
finddir=$(echo $name|sed 's/.*bal_001\(.*\)....\.dat/\1/')
[ $(echo $finddir|cut -c7-) = "888" ] && continue
jgname=$(awk -F"[# :]*" 'NR==5 {print $3}' $name)
jgsum=$(awk -F"|" 'END{print $3}' $name)
echo ${finddir}"\t"${jgname}"\t"${jgsum} >>~/yetj.txt
done
[ -s ~/yetj.txt ] && { clear ; awk 'BEGIN{printf("\n%30s\n\n%-12s\n%-12s%-25s%-18s\n\n",\
"余 额 查 询 表","统计日期: '$day'","机构号","网点名","余额")}
{printf("%-12s%-25s%-18.2f\n",$1,$2,$3) |"sort -n";sum+=$3}
END{close("sort -n");printf("\n%-12s%-25.2f\n","合计",sum)}' ~/yetj.txt ; } || \
echo "\n 无此统计报表\n "