#!/bin/bash
# 重新执行指定批量,运行一次执行一个月的时间跨度。读取配置文件$APPHOME/etc/reBatch.conf
# 用法: ./reBatch.sh 截止到月份的日期 例如: ./reBatch.sh 2014-06
. /etc/profile
. ~/.bashrc
arg=$1
start_date="${arg}-01"
end_date=${arg}-01
count=1
log_file=$APPHOME/log/reBatch_${arg}.log
cat /dev/null > $log_file
db2 +o connect to $DBNAME user $DBUSER using $DBPWD
if [ $# -ne 1 ];then
echo "传参错误!用法: ./reBatch.sh 截止到月份的日期 例如: ./reBatch.sh 2014-06"
exit 1
elif [ $# -eq 1 ];then
db2 +o "values date('$start_date')"
if [ $? -ne 0 ];then
echo "传参错误!用法: ./reBatch.sh 截止到月份的日期 例如: ./reBatch.sh 2014-06"
exit 1
else
end_date=`db2 -x "values date('$start_date') + 1 months - 1 days"`
count=`db2 -x "values days('$end_date')-days('$start_date')"`
count=$(($count+2))
fi
fi
i=1
while(($i<$count))
do
batch_date=$arg
if [ $i -le 9 ];then
batch_date=${arg}-0${i}
else
batch_date=${arg}-${i}
fi
db2 "update batch.BCH_MAINBATCHINF set curtstate='1', curtbatchdate=current date"| tee -a $log_file
db2 "update batch.BCH_SUBBATCHINF set curtstate='3', curtbatchdate=current date"| tee -a $log_file
cat $APPHOME/etc/reBatch.conf | grep -v "^#" | while read subject_id main_batch_id sub_batch_id prog_name other_args
do
echo "启动 $prog_name $DBNAME $DBUSER $DBPWD $batch_date $subject_id $main_batch_id $sub_batch_id $other_args ." | tee -a $log_file
$prog_name $DBNAME $DBUSER $DBPWD $batch_date $subject_id $main_batch_id $sub_batch_id $other_args 2>&1 | tee -a $log_file
if [ $? -ne 0 ]
then
echo "异常退出" | tee -a $log_file
exit
fi
date | tee -a $log_file
done
i=$(($i+1))
if [ $i -eq $count ];then
db2 "update batch.BCH_MAINBATCHINF set curtstate='3', curtbatchdate=current date"| tee -a $log_file
db2 "update batch.BCH_SUBBATCHINF set curtstate='3', curtbatchdate=current date"| tee -a $log_file
fi
done
db2 connect reset | tee -a $log_file
echo `date`"重跑${arg}月的批量结束" | tee -a $log_file