分类: LINUX
2011-06-10 11:11:50
#####################################################################################
##营收全业务稽核Ftp脚本(日志文件为/usr1/bb/bbwh/lin/JHFtplog)
#####################################################################################
#####################################################################################
#ip地址
ip_port=10.244.155.23;
#用户名
user=revencoacct;
#密码
pass=acctk7KjfoE;
#出账月文件目录
rmtCZMdir=/RAdata/CZSR/MM;
#出账日文件目录
rmtCZDdir=/RAdata/CZSR/DD;
#欠费月文件目录
rmtQFMdir=/RAdata/BSDT/MM;
#欠费日文件目录
rmtQFDdir=/RAdata/BSDT/DD;
#营收稽核日文件目录
rmtYSDdir=/RAdata/QTYS/DD;
#营收稽核月文件目录
rmtYSMdir=/RAdata/QTYS/MM;
#预存款日文件目录
rmtYCKDdir=/RAdata/BSYC/DD;
#预存款月文件目录
rmtYCKMdir=/RAdata/BSYC/MM;
#####################################################################################
#####################################################################################
###得到指定日期的前一天 参数为YYYYMMDD
getPreDay()
{
year=`expr substr $1 1 4`
mon=`expr substr $1 5 2`
day=`expr substr $1 7 2`
day=`expr $day - 1`
if [ $day -eq 0 ]
then
mon=`expr $mon - 1`
if [ $mon -eq 0 ]
then
mon=12
year=`expr $year - 1`
fi
lastline=`cal $mon $year | grep "[0-9]" | tail -1`
day=`echo $lastline | awk '{print $NF}'`
fi
if [[ $mon -lt 10 && `expr length ${mon}` -eq 1 ]]
then
mon="0"$mon
fi
if [[ $day -lt 10 && `expr length ${day}` -eq 1 ]]
then
day="0"$day
fi
echo "$year$mon$day"
}
###得到指定月份的前一月
getPreMonth()
{
year=`expr substr $1 1 4`
mon=`expr substr $1 5 2`
mon=`expr $mon - 1`
if [ $mon -eq 0 ]
then
year=`expr $year - 1`
mon=12
fi
if [ $mon -lt 10 ]
then
mon="0"$mon
fi
echo "$year$mon"
}
###得到地市编码
getAreaCode()
{
set -A cityName GZ SZ ZH FS ST HZ ZJ JM ZQ SG MZ DG ZS MM SW CZ JY YJ QY HY YF
set -A cityCode 01 02 03 04 05 06 07 08 09 10 11 12 13 15 16 17 18 19 21 22 23
index=0
while [ $index -lt 21 ]
do
if [ $1 == ${cityName[$index]} ]
then
echo ${cityCode[$index]}
return
fi
index=$index+1
done
echo "-1"
}
#####################################################################################
#####################################################################################
MONTH=`date +%Y%m`
DAY=`date +%Y%m%d`
getPreDay ${DAY} | read PreDay
getPreDay ${PreDay} | read PrePreDay
getPreDay ${PrePreDay} | read PrePrePreDay
getPreMonth ${MONTH} | read PreMonth
getPreMonth ${PreMonth} | read PrePreMonth
getPreMonth ${PrePreMonth} | read PrePrePreMonth
JHFtplog="/usr1/bb/bbwh/lin/JHFtplog_"$DAY
for city in cz dg fs gz hy hz jy mm mz qy sg st sw sz yf yj zh zj zq zs jm
do
###稽核文件备份目录
JHBakFile="/usr1/bb3/data/${city}/jihe_file_bak/"
###稽核文件临时目录
JHTmpFile="/usr1/bb3/data/${city}/jihe_tmp/"
###删除稽核备份目录下的文件
for file in `ls ${JHBakFile}`
do
###如果是月文件
if [ `expr substr $file 11 3` == "_M_" ]
then
FileMonth=`expr substr $file 14 6`
###删除三个月之前的文件
if [ $FileMonth -lt $PrePrePreMonth ]
then
echo "rm ${JHBakFile}${file}" >> $JHFtplog
rm ${JHBakFile}${file}
fi
fi
###如果是日文件
if [ `expr substr $file 11 3` == "_D_" ]
then
FileDay=`expr substr $file 14 8`
###删除三天前的文件
if [ $FileDay -lt $PrePrePreDay ]
then
echo "rm ${JHBakFile}${file}" >> $JHFtplog
rm ${JHBakFile}${file}
fi
fi
done
###删除稽核临时目录下保存的QC和BG文件
for file in `ls ${JHTmpFile}`
do
tmpFileDay=`expr substr $file 22 8`
###删除三天前的文件
if [ $tmpFileDay -lt $PrePrePreDay ]
then
echo "rm ${JHTmpFile}${file}" >> $JHFtplog
rm ${JHTmpFile}${file}
fi
done
done
#for city in cz dg fs gz hy hz jy mm mz qy sg st sw sz yf yj zh zj zq zs jm
for city in gz zs jm
do
echo $city | tr '[a-z]' '[A-Z]'|read CITY
getAreaCode ${CITY} | read AREACODE
jihe_file="/usr1/bb3/data/${city}/jihe_file/"
###ZHC1(费用回收) ZHC3(账目变更) ZHC6(期末余额)
for file in ZHC1 ZHC3 ZHC6
do
if [ ! -e "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_01" ]
then
echo "touch ${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_01" >> $JHFtplog
touch "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_01"
fi
if [ ! -e "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_02" ]
then
echo "touch ${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_02" >> $JHFtplog
touch "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_02"
fi
if [ ! -e "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_03" ]
then
echo "touch ${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_03" >> $JHFtplog
touch "${jihe_file}RA_${file}_${AREACODE}_D_${PreDay}_03"
fi
done
done
for city in cz dg fs gz hy hz jy mm mz qy sg st sw sz yf yj zh zj zq zs jm
do
cd /usr1/bb3/data/${city}/jihe_file;
echo "开始传送${city}的稽核文件" >> $JHFtplog
echo "当前目录为/usr1/bb3/data/${city}/jihe_file" >> $JHFtplog
JHbakdir=/usr1/bb3/data/${city}/jihe_file_bak
JHtmpdir=/usr1/bb3/data/${city}/jihe_tmp
for file in `ls`
do
awk '
BEGIN{
CQY["WZFX"] ="CZM"; CQY["TZFX"] ="CZM"; CQY["GZJF"] ="CZM";CQY["TCYX"] ="CZM"; CQY["TCCF"] ="CZM";
CQY["CZYS"] = "CZM";CQY["FXYS"] = "CZM"; CQY["YXYS"] = "CZM";CQY["CZQR"] = "CZM";
CQY["FRRT"] = "QFM"; CQY["FRRD"] = "QFM"; CQY["ABCL"] = "QFM"; CQY["BSWF"] = "QFM"; CQY["SUAR"] = "QFM";
CQY["SUAA"] = "QFM"; CQY["BSBA"] = "QFM"; CQY["BSBG"] = "QFM";CQY["FRST"] = "QFM"; CQY["ABSI"] = "QFM";
CQY["SFRT"] = "QFM"; CQY["SADB"] = "QFM"; CQY["TSYJ"] = "QFM"; CQY["AABT"] = "QFM"; CQY["BSBI"] = "QFM"; CQY["BSDT"] = "QFM";
CQY["HZTS"] = "YSM"; CQY["SSTJ"] = "YSM";CQY["JZMX"] = "YSD";CQY["QTYS"] = "YSM";CQY["YHHS"] = "YSM";
CQY["ZHB1"] = "YCKM";CQY["ZHB3"] = "YCKM";CQY["ZHB5"] = "YCKM";CQY["ZHB7"] = "YCKM";CQY["ZHD8"] = "YCKM";
CQY["BSYC"] = "YCKM";CQY["TSMX"] = "YCKD";CQY["ZHC0"] = "YCKD";CQY["ZHC6"] = "YCKD";CQY["ZHC3"] = "YCKD";CQY["ZHC7"] = "YCKD";CQY["ZHC1"] = "YCKD";CQY["ZHC5"] = "YCKD";
###先判断是否是预存款类型的文件
if(substr(FILENAME, 4, 4) in CQY && (CQY[substr(FILENAME, 4, 4)] == "YCKM"||CQY[substr(FILENAME, 4, 4)] == "YCKD"))
{
print CQY[substr(FILENAME, 4, 4)];
}
###按月的文件
else if(substr(FILENAME, 4, 4) in CQY && substr(FILENAME, 11, 3) != "_D_" )
{
print CQY[substr(FILENAME, 4, 4)];
}
else
{
###营收类按天汇总文件RA_QTYS_00_D_YYYYMMDD_00_BS
###银行划帐及其托收统计报表,前台营收RA_HZTS_XX_D_YYYYMMDD_00
###实收营业统计表(银行进帐),前台营收RA_SSTJ_XX_D_YYYYMMDD_00
###银行进账明细,前台营收RA_JZMX_XX_D_YYYYMMDD_00
if( (substr(FILENAME, 4, 4) == "QTYS" || substr(FILENAME, 4, 4) == "SSTJ" || substr(FILENAME, 4, 4) == "HZTS"||substr(FILENAME, 4, 4) == "JZMX") && substr(FILENAME, 11, 3) == "_D_")
{
print "YSD";
}
###欠费类按天汇总文件RA_BSDT_00_D_YYYYMMDD_00_BS(目前无)
else if(substr(FILENAME, 4, 4) == "BSDT" && substr(FILENAME, 11, 3) == "_D_")
{
print "QFD";
}
###出账类按天汇总文件RA_CZQR_00_D_YYYYMMDD_00_BS(目前无)
else if(substr(FILENAME, 4, 4) == "CZQR" && substr(FILENAME, 11, 3) == "_D_")
{
print "CZD";
}
###预存款类按天汇总文件RA_BSYC_00_D_YYYYMMDD_00_BS
else if(substr(FILENAME, 4, 4) == "BSYC" && substr(FILENAME, 11, 3) == "_D_")
{
print "YCKD";
}
else
{
print "error";
}
}
}
' $file | read mode
if [ $mode == "CZM" ]
then
rmtfile=${rmtCZMdir}/$file;
tmpdir=${rmtCZMdir}/tmp
tmpfile=${tmpdir}/$file;
elif [ $mode == "CZD" ]
then
rmtfile=${rmtCZDdir}/$file;
tmpdir=${rmtCZDdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "QFM" ]
then
rmtfile=${rmtQFMdir}/$file;
tmpdir=${rmtQFMdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "QFD" ]
then
rmtfile=${rmtQFDdir}/$file;
tmpdir=${rmtQFDdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "YSD" ]
then
rmtfile=${rmtYSDdir}/$file;
tmpdir=${rmtYSDdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "YSM" ]
then
rmtfile=${rmtYSMdir}/$file;
tmpdir=${rmtYSMdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "YCKM" ]
then
rmtfile=${rmtYCKMdir}/$file;
tmpdir=${rmtYCKMdir}/tmp;
tmpfile=${tmpdir}/$file;
elif [ $mode == "YCKD" ]
then
rmtfile=${rmtYCKDdir}/$file;
tmpdir=${rmtYCKDdir}/tmp;
tmpfile=${tmpdir}/$file;
else
###如果是变更文件
if [ `expr substr $file 7 11` == "DAYWOFFCUST" ]
then
mv $file $JHtmpdir
echo "将变更文件${file}备份到${JHtmpdir}目录中" >> $JHFtplog
else
echo "error:"$file"文件类型错误" >> $JHFtplog
fi
continue;
fi
echo "稽核文件$file开始" >> $JHFtplog
(
echo user $user $pass;
###二进制传输模式
echo bin;
echo copy;
###关闭交互模式
echo prompt;
###切换远程目录
echo cd $tmpdir;
###上传文件
echo put $file;
###删除远程目录文件
echo del $rmtfile;
###重命名文件
echo rename $tmpfile $rmtfile;
###退出FTP连接
echo bye;
) | ftp -n $ip_port
echo "ftp return:"$?
echo "稽核文件$file传送结束" >> $JHFtplog
mv $file $JHbakdir;
echo "将稽核文件${file}备份到${JHbakdir}目录中" >> $JHFtplog
done
done
#####################################################################################