shell脚本案例赏析

#!/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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值