#!/bin/sh
#===============================================================================
# SCRIPT ID : 
# SCRIPT NAME : 
# CREATE DATE : 
# AUTHOR : 
# COPYRIGHT : 
# VARIABLES
#===============================================================================
#===============================================================================
# 环境设置
#===============================================================================
##### 变量定义 #####
#JOB ID
JOBID=`basename $0`;export JOBID

STEPID="";export STEPID
#
FILE_PATH="/xxxx/";export FILE_PATH
#
BIZINIT="BIZINIT";export BIZINIT
#
BIZCOMMON="BIZCOMMON";export BIZCOMMON
#
REC_CNT="";export REC_CNT
#等待时间
WAIT_TIME="180";export WAIT_TIME
#循环次数
REPEAT_COUNT="5";export REPEAT_COUNT

#REDER fileName
READER_FILE="xxxx"; export READER_FILE
#REDER filePath
READER_DIR="/xxxx/"; export READER_DIR
#OF
OF_FILE="xxxx";export OF_FILE
#OF
OF_DIR="/xxxxx/";export OF_PATH

RECSIZE=363;export RECSIZE

#===============================================================================
# 
#===============================================================================
STEPID="00"
#--- ---
DATE=`date +"%Y/%m/%d %H:%M:%S"`
if [ -f ${FILE_PATH}${BIZINIT} ]
then
. ${FILE_PATH}${BIZINIT}
ret=$?
if [ ${ret} -ne 0 ]
then
echo "${DATE},${JOBID},Exe Error ${BIZINIT} [Return Code - ${ret}],${STEPID}"
exit ${JOB_EXIT_ERROR}
fi
else
echo "${DATE},${JOBID},Not Exist ${BIZINIT},${STEPID}"
exit ${JOB_EXIT_ERROR}
fi
#--- ---
DATE=`date +"%Y/%m/%d %H:%M:%S"`
if [ -f ${FILE_PATH}${BIZCOMMON} ]
then
. ${FILE_PATH}${BIZCOMMON}
ret=$?
if [ ${ret} -ne 0 ]
then
echo "${DATE},${JOBID},Exe Error ${BIZCOMMON} [Return Code - ${ret}],${STEPID}"
exit ${JOB_EXIT_ERROR}
fi
else
echo "${DATE},${JOBID},Not Exist ${BIZCOMMON},${STEPID}"
exit ${JOB_EXIT_ERROR}
fi
#===============================================================================
# job start
#===============================================================================
##### JOB log start #####
doLogWrite "INFO, JOB START"
#===============================================================================
# Step10 IF file check
#===============================================================================
STEPID="10"
#step log 
doLogWrite "INFO, STEP${STEPID} START"

#--- dateFile check ---
CNT=0
while :
do
if [ -f ${READER_DIR}${READER_FILE} ]
then
break
fi

CNT=`expr ${CNT} + 1`
doLogWrite "INFO, Repeat Count ${CNT}"
if [ "${CNT}" -eq "${REPEAT_COUNT}" ]
then
break
else
sleep ${WAIT_TIME}
fi
done
#--- 处理结果判断 ---
case ${CNT} in
#存在的情况下
${REPEAT_COUNT}) doLogWrite "ERROR, Not Exist ${READER_FILE}"
exit ${JOB_EXIT_ERROR};;
#不存在的情况
*) doLogWrite "INFO, Exist ${READER_FILE}"
esac

#--- file create start ---
ACD_CSS='A'

REC_ID='TYI'

PLACE_CD='010'

YMD_TODAY=`date +"%Y%m%d"`
DATE=`date +"%Y%m%d"`
echo "当前系统时间=${YMD_TODAY}">> ${LOG_PATH}/${JOBID}_${DATE}.log

SCHDL_TODAY='A'

YMD_PREV=`date +%Y%m%d -d "-1 day"`
DATE=`date +"%Y%m%d"`
echo "系统时间前一天=${YMD_PREV}">> ${LOG_PATH}/${JOBID}_${DATE}.log

TMP_DATE=`date +%Y%m01`
CLOSING_YMD_PREV=`date -d"$TMP_DATE last day" +%Y%m%d`
DATE=`date +"%Y%m%d"`
echo "上个月最后一天=${CLOSING_YMD_PREV}">> ${LOG_PATH}/${JOBID}_${DATE}.log

CLOSING_YMD=`date -d"$(date -d"1 month" +"%Y%m01") -1 day" +"%Y%m%d"`
DATE=`date +"%Y%m%d"`
echo "本月最后一天=${CLOSING_YMD}">> ${LOG_PATH}/${JOBID}_${DATE}.log

TMP_DATE=`date -d '2month' +%Y%m01`
CLOSING_YMD_NEXT=`date -d "$TMP_DATE last day" +%Y%m%d`
DATE=`date +"%Y%m%d"`
echo "下一月最后一天=${CLOSING_YMD_NEXT}">> ${LOG_PATH}/${JOBID}_${DATE}.log

INTVL_SPACE=' '

WORK_BIT='X'
YMD_NEXT='';
YMD='';

#明天    CHAR    8    YMD_NEXT
TMP_DATE=`date +"%Y%m%d"`
YMD=`grep "${TMP_DATE}" ${READER_DIR}${READER_FILE}`
echo "YMD===="$YMD
if [ ${YMD} ]
then
YMD_NEXT=`date +%Y%m%d -d "+2 day"`

else 
YMD_NEXT=`date +%Y%m%d -d "+1 day"`
fi
echo "=${YMD};===${YMD_NEXT}">> ${LOG_PATH}/${JOBID}_${TMP_DATE}.log
echo ${ACD_CSS}${REC_ID}${PLACE_CD}${YMD_TODAY}${SCHDL_TODAY}${YMD_PREV}${YMD_NEXT}${CLOSING_YMD_PREV}${CLOSING_YMD}${CLOSING_YMD_NEXT}"${INTVL_SPACE}"${WORK_BIT}>${OF_DIR}${OF_FILE}
FOOTER_SPACE=' '
echo ${YMD_TODAY}'FNSSTYIO 000000010362'"${FOOTER_SPACE}">>${OF_DIR}${OF_FILE}

#cat ${READER_DIR}${READER_FILE} | while read YMD
#do
#    if [ "${YMD}" -eq "${TMP_DATE}" ]
#    then
#    YMD_NEXT=`date +%Y%m%d -d "+2 day"`
#    
#    else 
#    YMD_NEXT=`date +%Y%m%d -d "+1 day"`
#    fi
#    echo "文件中的日期=${YMD};明天===${YMD_NEXT}"
#    echo ${ACD_CSS}${REC_ID}${PLACE_CD}${YMD_TODAY}${SCHDL_TODAY}${YMD_PREV}${YMD_NEXT}${CLOSING_YMD_PREV}${CLOSING_YMD}${CLOSING_YMD_NEXT}"${INTVL_SPACE}"${WORK_BIT}>${OF_DIR}${OF_FILE}
#    FOOTER_SPACE=' '
#    echo ${YMD_TODAY}'FNSSTYIO 000000010362'"${FOOTER_SPACE}">>${OF_DIR}${OF_FILE}
#done

#check 
FILESIZE=`ls -l ${OF_DIR}${OF_FILE}|awk '{print $5}'`
DATE=`date +"%Y%m%d"`
echo "FILE SIZE ="${FILESIZE} >> ${LOG_PATH}/${JOBID}_${DATE}.log
if [ `expr ${FILESIZE} % ${RECSIZE}` -ne 0 ]
then
DATE=`date +"%Y%m%d"`
echo "${DATE},${JOBID}, error [Return Code - 1],${STEPID}"
echo ${OF_FILE}"文件长度不对!!" >> ${LOG_PATH}/${JOBID}_${DATE}.log
exit ${JOB_EXIT_ERROR};
fi

#--- 结果判断 ---
ret=$?
case ${ret} in

0) doLogWrite "INFO, ${OF_FILE} create Success";;

1) doLogWrite "FATAL, ${OF_FILE} create Fail"
exit ${JOB_EXIT_ERROR};;
2) doLogWrite "WARN, ${OF_FILE} create Warning End";;
esac
doLogWrite "INFO, ${JOBID} End"
#===============================================================================
# end
#===============================================================================
STEPID="99"

doLogWrite "INFO, STEP${STEPID} END"

exit ${JOB_EXIT_NORMAL}

 

posted on 2018-09-13 10:14  清风徐来随心  阅读(1021)  评论(0编辑  收藏  举报