文件Common.sh:
SCRIPT_DIR=${BV_EOS_BAT_ROOT}/script
LIB_DIR=${BV_EOS_BAT_ROOT}/lib
SEND_DIR=${BV_EOS_BAT_ROOT}/send
SEND_CFG=${BV_EOS_BAT_ROOT}/send/cfg
SEND_TRANS=${BV_EOS_BAT_ROOT}/send/trans
SEND_TRANS_ERR=${BV_EOS_BAT_ROOT}/send/trans_err
SEND_WORK=${BV_EOS_BAT_ROOT}/send/work
SEND_BACKUP=${BV_EOS_BAT_ROOT}/send/backup
RECV_DIR=${BV_EOS_BAT_ROOT}/recv
RECV_CFG=${BV_EOS_BAT_ROOT}/recv/cfg
RECV_TRANS=${BV_EOS_BAT_ROOT}/recv/trans
RECV_TRANS_ERR=${BV_EOS_BAT_ROOT}/recv/trans_err
RECV_WORK=${BV_EOS_BAT_ROOT}/recv/work
RECV_BACKUP=${BV_EOS_BAT_ROOT}/recv/backup
STG_DIR=${BV_EOS_BAT_ROOT}/stg
STG_CFG=${BV_EOS_BAT_ROOT}/stg/cfg
STG_TRANS=${BV_EOS_BAT_ROOT}/stg/trans
STG_TRANS_ERR=${BV_EOS_BAT_ROOT}/stg/trans_err
STG_WORK=${BV_EOS_BAT_ROOT}/stg/work
STG_BACKUP=${BV_EOS_BAT_ROOT}/stg/backup
QRY_CFG=${BV_EOS_BAT_ROOT}/queryindex/cfg
MAIL_ERR=${BV_EOS_BAT_ROOT}/mail/send_err
AFFI_CFG=${BV_EOS_BAT_ROOT}/affi_ls/cfg
STATUS_DIR=${BV_EOS_BAT_ROOT}/status
AFFI_DIR=${BV_EOS_BAT_ROOT}/affi_ls
AFFI_TRANS=${BV_EOS_BAT_ROOT}/affi_ls/trans
AFFI_TRANS_ERR=${BV_EOS_BAT_ROOT}/affi_ls/trans_err
AFFI_WORK=${BV_EOS_BAT_ROOT}/affi_ls/work
AFFI_BACKUP=${BV_EOS_BAT_ROOT}/affi_ls/backup
LOG_DIR=${BV_EOS_BAT_ROOT}/log
SEND_LOG=${BV_EOS_BAT_ROOT}/log/send
RECV_LOG=${BV_EOS_BAT_ROOT}/log/recv
STAG_LOG=${BV_EOS_BAT_ROOT}/log/stg
AFFI_LOG=${BV_EOS_BAT_ROOT}/log/affi
MAIL_LOG=${BV_EOS_BAT_ROOT}/log/mail
NOTIF_LOG=${BV_EOS_BAT_ROOT}/log/notif
BATCHSERVICENAME=EosBatch
HULFT_PATH=/opt/hulft/bin
export BV_EOS_BAT_ROOT
export SCRIPT_DIR
export LIB_DIR
export SEND_DIR
export SEND_CFG
export SEND_TRANS
export SEND_TRANS_ERR
export SEND_WORK
export SEND_BACKUP
export RECV_DIR
export RECV_CFG
export RECV_TRANS
export RECV_TRANS_ERR
export RECV_WORK
export RECV_BACKUP
export STG_DIR
export STG_CFG
export STG_TRANS
export STG_TRANS_ERR
export STG_WORK
export STG_BACKUP
export STATUS_DIR
export AFFI_DIR
export AFFI_TRANS
export AFFI_TRANS_ERR
export AFFI_WORK
export AFFI_BACKUP
export LOG_DIR
export SEND_LOG
export RECV_LOG
export STAG_LOG
export AFFI_LOG
export MAIL_LOG
export NOTIF_LOG
export BATCHSERVICENAME
export HULFT_PATH
. ${BV_VAR_ROOT}/etc/bv1to1.conf.sh
export MAIL_LIB; MAIL_LIB=$BV1TO1_VAR/eosCommon/lib
classpath=$classpath:$LIB_DIR/eosbatch.jar:$MAIL_LIB/activation.jar:$MAIL_LIB/mail.jar:$MAIL_LIB/eoscommon.jar:$LIB_DIR/eosonline.jar:$LIB_DIR/struts.jar:$BV1TO1/CLASSES/commercecore.jar:$BV1TO1/webapps/webappCommon.jar
WriteErrLog( )
{
if [ -z $4 ]
then
LEVEL="ERROR"
else
LEVEL=$4
fi
TIME=`date '+%Y/%m/%d %H:%M:%S'`
case $1 in
1) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${RECV_LOG}/$3
;;
2) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${SEND_LOG}/$3
;;
3) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${STAG_LOG}/$3
;;
4) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${AFFI_LOG}/$3
;;
5) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${MAIL_LOG}/$3
;;
6) echo "ERROR, $TIME, $LEVEL ${MODULE}で $2 " >> ${NOTIF_LOG}/$3
;;
esac
}
WriteNormalLog( )
{
if [ -z $3 ]
then
LEVEL="INFO"
else
LEVEL=$3
fi
TIME=`date '+%Y/%m/%d %H:%M:%S'`
case $1 in
1) logger -p local2.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
2) logger -p local1.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
3) logger -p local3.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
4) logger -p local4.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
5) logger -p local5.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
6) logger -p local6.info "$LEVEL, $TIME, ${MODULE}で $2"
;;
esac
}
StatusManager( )
{
if [ $# -eq "1" ]
then
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $1
VALUE=$?
if [ $VALUE -ne "1" ]
then
return $VALUE
else
return $VALUE
fi
elif [ $# -eq "2" ]
then
if [ "$2" = "FLAG" ]
then
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $1 $2
VALUE=$?
if [ $VALUE -ne "1" ]
then
return $VALUE
else
return $VALUE
fi
else
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $1 $2
VALUE=$?
if [ $VALUE -ne "1" ]
then
return 0
else
return 1
fi
fi
elif [ $# -eq "3" ]
then
if [ $3 -eq "0" ]
then
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $1 $2
VALUE=$?
if [ $VALUE -ne "1" ]
then
return 0
else
return 1
fi
else
return 1
fi
elif [ $# -eq "4" ]
then
if [ $3 -eq "1" ]
then
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $1 $2
VALUE=$?
if [ $VALUE -ne "1" ]
then
$BV1TO1/bin/java -cp $classpath -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusFlagManager $4 "3"
VALUE=$?
if [ $VALUE -ne "1" ]
then
return 0
else
return 1
fi
else
return 1
fi
else
return 1
fi
else
return 1
fi
}
文件dump.sh
#!/bin/bash
BV_VAR_ROOT=/home/bvsys/bv1to1
BV_EOS_BAT_ROOT=$BV_VAR_ROOT/batch
. $BV_EOS_BAT_ROOT/script/Common.sh
STG_DUMP_DIR=${STG_WORK}/$1
DMPFILE="$1"".tar"
HOSTNAME="$2"
USER="bvsys"
PASSWORD="0WE5jKaU"
DATA_FLG=$1
CFG_FILE="$1".lst""
SHELLNAME=`basename $0`
TMPPROGRAMID=`echo $SHELLNAME|cut -d. -f1`
PROGRAMID="Stg""${DATA_FLG}"
ERR_FILE_HEAD="$TMPPROGRAMID"_"$DATA_FLG"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
MODULE="Out put batch AP"
WriteNormalLog "3" "Start"
if [ $# -ne "2" ]
then
WriteErrLog "3" "SMS6002E Wrong Parameter" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Batch AP error end" "ERROR"
exit 2
fi
StatusManager $PROGRAMID "FLAG"
STATUS=$?
if [ $STATUS -eq "1" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
WriteErrLog "3" "SMS6005E Take status errors。" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Batch AP error end" "ERROR"
exit 2
fi
if [ $STATUS -eq "3" ]
then
WriteNormalLog "3" "Before Ap is processing" "WARNING"
exit 1
fi
if [ $STATUS -eq "5" ]
then
WriteNormalLog "3" "Not do remains and Ap nomally end" "ERROR"
exit 0
fi
$BV1TO1/bin/java -cp $classpath -DTimePath=${STG_WORK} -DBVService=$BATCHSERVICENAME com.nec.jp.eosweb.batch.common.StatusTimeManager $PROGRAMID
STATUS=$?
if [ $STATUS -ne "0" ] || [ ! -e ${STG_WORK}/$PROGRAMID".TIME" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
#STATUS = 3
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SMS6006E take start time error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
exec 4<&0 0<${STG_WORK}/$PROGRAMID".TIME"
read STGSTIME
exec 0<&4
rm -f ${STG_WORK}/$PROGRAMID".TIME"
if [ -z "$STGSTIME" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
#STATUS= 3
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SMS6006E take start time error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
StatusManager $PROGRAMID 1
STATUS=$?
if [ $STATUS -eq "1" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
if [ ! -e ${STG_CFG}/${CFG_FILE} ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
#STATUS = 3
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
#error logを出力する
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SMS6007E parameter is error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
if [ ! -d ${STG_DUMP_DIR} ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
#error logを出力する
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6123E error directory" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
STG_LOG_FILE="stg_common.log"
cd ${STG_DUMP_DIR}
STGNSTIME=`date '+%Y/%m/%d %H:%M:%S'`
YEARTIME=`echo $STGSTIME | awk '{print substr($0,3,2)}'`
MMDDTIME=`echo $STGSTIME | awk '{print substr($0,6,5)}'`
HMSTIME=`echo $STGSTIME | awk '{print substr($0,12,8)}'`
DUMPTIME="$MMDDTIME""/""$YEARTIME"" ""$HMSTIME"
$BV1TO1/bin/bv_stg_tool dump "$DUMPTIME" -n ${STG_CFG}/${CFG_FILE} >> ${STAG_LOG}/"${STG_LOG_FILE}"
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
$BV1TO1/bin/java -cp $classpath -DTimePath=${LIB_DIR} -DBVService=$BATCHSERVICENAME com.batch.common.StatusTimeManager ${PROGRAMID} "/"$STGNSTIME/""
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
StatusManager $PROGRAMID 3
STATUS_TMP=$?
if [ ${STATUS_TMP} -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
if [ $STATUS -eq "4" ] || [ $STATUS -eq "3" ]
then
WriteNormalLog "3" "operated object is not exist" "WARNING"
exit 0
fi
WriteErrLog "3" "SMD6311E dump error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
STGNETIME=`date '+%Y/%m/%d %H:%M:%S'`
$BV1TO1/bin/java -cp $classpath -DTimePath=${LIB_DIR} -DBVService=$BATCHSERVICENAME com.batch.common.StatusTimeManager ${PROGRAMID} "/"$STGNSTIME/"" "/"$STGNETIME/""
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
DUMP_TIME=`date '+%Y%m%d%H%M%S'`
DUMP_FILE=${DATA_FLG}.${DUMP_TIME}."tar"
tar cvf ${DUMP_FILE} current*
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
ERR_DIR=${DATA_FLG}."${ERR_TIME}"
mkdir ${STG_TRANS_ERR}/${ERR_DIR}
STATUS=$?
if [ $STATUS -eq "0" ]
then
mv ${STG_DUMP_DIR}/* ${STG_TRANS_ERR}/${ERR_DIR}/
fi
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6114E tar error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
cd ${SCRIPT_DIR}
mv ${STG_DUMP_DIR}/${DUMP_FILE} ${STG_TRANS}/${DUMP_FILE}
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
mv ${STG_DUMP_DIR}/${DUMP_FILE} ${STG_TRANS_ERR}/${DUMP_FILE}
rm -rf ${STG_DUMP_DIR}/*
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6115E copy file error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
rm -r ${STG_DUMP_DIR}/*
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
mv ${STG_TRANS}/${DUMP_FILE} ${STG_TRANS_ERR}/${DUMP_FILE}
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6116E Delete file error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
#ftp transfer file
FTP_LOG="ftp.log"
sftp -vn << EOF > ${STAG_LOG}/"${FTP_LOG}"
open $HOSTNAME
user $USER $PASSWORD
binary
cd ${STG_TRANS}
put ${STG_TRANS}/${DUMP_FILE}
quit
EOF
grep "226 Transfer complete." ${STAG_LOG}/"${FTP_LOG}"
STATUS=$?
rm -f ${STAG_LOG}/"${FTP_LOG}"
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
mv ${STG_TRANS}/${DUMP_FILE} ${STG_TRANS_ERR}/${DUMP_FILE}
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6117E ftp transfer file error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
mv ${STG_TRANS}/${DUMP_FILE} ${STG_BACKUP}/${DUMP_FILE}
STATUS=$?
if [ $STATUS -ne "0" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
mv ${STG_TRANS}/${DUMP_FILE} ${STG_TRANS_ERR}/${DUMP_FILE}
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -ne "0" ]
then
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
fi
WriteErrLog "3" "SFL6123E copy file to backup directory error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
StatusManager $PROGRAMID 3
STATUS=$?
if [ $STATUS -eq "1" ]
then
MODULE="Out put batch AP"
ERR_TIME=`date '+%Y%m%d%H%M%S'`
ERR_FILE_NAME="${ERR_FILE_HEAD}"_"${ERR_TIME}".err
WriteErrLog "3" "SMS6003E make status equal 3 error" "${ERR_FILE_NAME}"
WriteNormalLog "3" "Ap abort" "ERROR"
exit 2
fi
WriteNormalLog "3" "Ap normally end"
exit 0