【Linux脚本学习案例】shell脚本多通道并发执行存储过程

时间:2022-06-09 19:20:50

使用shell脚本开启多个子任务并发调用存储过程,存储过程按照通道处理数据,提高效率:

外层调用脚本:

#!/bin/sh
#--------------------------------------------------------------------
# Fuction:调用脚本
# Version: 1.0
#-------------------------------------------------------------------- . ~/.profile . /web/interface/common/FuncCommon.def
#######################公共配置###############################################
#当前时间 yyyymmdd
CURDATE=`date +%Y%m%d%H%M%S`
#执行文件路径
BIN_PATH=~/interface
#日志文件
LOG_PATH=~/interface/log
#配置文件路径
INI_PATH=~/interface/ini/
#每次每通道处理数量
PER_NUM= echo `date +%H\:%M\'%S\"` "脚本PERIODIC_CALL.sh开始..." vacgwms=`ps -ef|grep -v grep|grep PERIODIC_CALL.sh |wc -l`
if [ $vacgwms -gt ]
then
echo `date +%H\:%M\'%S\"` "上次PERIODIC_CALL.sh未结束..."
exit
fi loop=
while(($loop<))
do echo "通道:"${loop}"开始......"
#.先判断lock文件是否存在
cd ${INI_PATH}
if [ -e ${loop}_*.lock ]
then
echo "通道锁文件:"${loop}.lock"仍然存在,上次存储执行未结束,下次调用再校验"
loop=`expr $loop + `
continue else
#创建锁文件
LOCK_NAME=${loop}_${CURDATE}.lock
touch ${LOCK_NAME}
echo "通道锁文件:"${LOCK_NAME}"创建成功" #.调用存储
#nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM >> /dev/null >${LOG_PATH}/core.log &
nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM >> ${LOG_PATH}/core.log >& &
#nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM > /dev/null &
fi loop=`expr $loop + ` done; wait echo `date +%H\:%M\'%S\"` "脚本PERIODIC_CALL.sh结束..."

内层执行脚本:

#!/bin/sh
#--------------------------------------------------------------------
# Fuction:执行存储脚本
# Version: 1.0
#-------------------------------------------------------------------- . ~/.profile ORACLE_HOME=/oracle/product/10.2./db
TNS_ADMIN=/ngbss/mddms/etc
export TNS_ADMIN
export ORACLE_HOME
. /web/interface/common/FuncCommon.def
#######################公共配置###############################################
#配置文件路径
INI_PATH=~/interface/ini/
#营业库连接
CONN=`/web/interface/passwd/pwd.sh CON_CC`
#短信配置
DEALDATE=`date +"%Y年%m月%d日%H时%M分"` echo `date +%H\:%M\'%S\"` "脚本CORE_EXEC.sh开始...通道:"$1",单次捞取数量:"$2
#1调用存储 RETINFO=`sqlplus -S $CONN << !
set heading off
set feedback off
set pages
set trimspool on
set serverout off
var V_RESULTCODE NUMBER;
var V_RESULTERRINFO VARCHAR2();
call PROC_PP($,$,:V_RESULTCODE, :V_RESULTERRINFO);
select :V_RESULTCODE ||','|| :V_RESULTERRINFO from dual;
EXIT ;
!` echo "存储过程返回信息:" $RETINFO
#echo ${RETINFO##*,}
RESULTCODE1=`echo $RETINFO|cut -c1`
RESULTCODE2=`echo $RETINFO|cut -c1-`
echo "RESULTCODE1:"$RESULTCODE1
echo "RESULTCODE2:"$RESULTCODE2 if [ $RESULTCODE1 == ]
then
# 删除锁文件
cd ${INI_PATH}
if [ -e ${}_*.lock ]
then
rm ${}_*.lock
echo 删除通道$1锁文件成功!
else
echo 未找到通道$1的锁文件
fi
elif [ $RESULTCODE2 == - ]
then
#存储过程报错 需要发短信通知
msg="ss2gnum#${DEALDATE}停开2G:存储过程PROC_PP,通道${1}报错:${RETINFO}"
echo $msg
(
sleep
echo $msg
sleep
echo "quit"
)| telnet ${REMOTE_IP} ${REMOTE_PORT}>./log/telnet_wls.log
fi echo `date +%H\:%M\'%S\"` "脚本CORE_EXEC.sh结束...通道:"$1",单次捞取数量:"$2