#!/bin/bash
# 用法: ./rebatch.sh 截止到月份的日期 例如: ./rebatch.sh 2014-06
. /etc/profile
. ~/.bashrc
arg=$1
start_date="$-01"
end_date=$-01
count=1
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))
fifi
i=1while(($i<$count))
do batch_date=$arg
if [ $i -le 9 ];then
batch_date=$-0$
else
batch_date=$-$
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
doecho "啟動 $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
fidate | 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
fidone
db2 connect reset | tee -a $log_file
echo `date`"重跑$月的批量結束" | tee -a $log_file
shell指令碼案例
bin bash for迴圈的使用 for num in 1 2 3 4 5 6 do echo num done bin bash a whoami read p 請輸入想要驗證的使用者名稱 b if b a then echo 是當前使用者 else echo 不是當前使用者,需示警 fi bi...
shell指令碼案例(提供思路)
1 define the execution environment of the script 定義指令碼的執行環境 執行指令碼用英文 usr bin bash 2 號代表注釋 是特例 3 指令碼資訊 author tang xiaoming created time 2019 05 07 11 ...
shell指令碼案例 二 HDFS檔案定期清理
當前環境的hdfs的空間使用率,即將達到95 手動清理比較繁瑣,需要寫個指令碼定期清理下最早5天的日誌量。方法之一 定期檢查hdfs的空間佔用率,若超過95 則刪除最早5天的日誌檔案。設定使用率閾值 查詢當前使用率,若達到閾值,查詢出最早5天的檔案 將查詢到的檔案刪除 linux shell可以用f...