使用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=500000 echo `date +%H\:%M\‘%S\"` "脚本PERIODIC_CALL.sh开始..." vacgwms=`ps -ef|grep -v grep|grep PERIODIC_CALL.sh |wc -l` if [ $vacgwms -gt 1 ] then echo `date +%H\:%M\‘%S\"` "上次PERIODIC_CALL.sh未结束..." exit 0 fi loop=0 while(($loop<50)) do echo "通道:"${loop}"开始......" #1.先判断lock文件是否存在 cd ${INI_PATH} if [ -e ${loop}_*.lock ] then echo "通道锁文件:"${loop}.lock"仍然存在,上次存储执行未结束,下次调用再校验" loop=`expr $loop + 1` continue else #创建锁文件 LOCK_NAME=${loop}_${CURDATE}.lock touch ${LOCK_NAME} echo "通道锁文件:"${LOCK_NAME}"创建成功" #2.调用存储 #nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM >> /dev/null 2>${LOG_PATH}/core.log & nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM >> ${LOG_PATH}/core.log 2>&1 & #nohup sh ${BIN_PATH}/CORE_EXEC.sh $loop $PER_NUM > /dev/null & fi loop=`expr $loop + 1` done; wait echo `date +%H\:%M\‘%S\"` "脚本PERIODIC_CALL.sh结束..."
内层执行脚本:
#!/bin/sh #-------------------------------------------------------------------- # Fuction:执行存储脚本 # Version: 1.0 #-------------------------------------------------------------------- . ~/.profile ORACLE_HOME=/oracle/product/10.2.0/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 0 set trimspool on set serverout off var V_RESULTCODE NUMBER; var V_RESULTERRINFO VARCHAR2(500); call PROC_PP($1,$2,: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-2` echo "RESULTCODE1:"$RESULTCODE1 echo "RESULTCODE2:"$RESULTCODE2 if [ $RESULTCODE1 == 0 ] then #2 删除锁文件 cd ${INI_PATH} if [ -e ${1}_*.lock ] then rm ${1}_*.lock echo 删除通道$1锁文件成功! else echo 未找到通道$1的锁文件 fi elif [ $RESULTCODE2 == -1 ] then #存储过程报错 需要发短信通知 msg="ss2gnum#${DEALDATE}停开2G:存储过程PROC_PP,通道${1}报错:${RETINFO}" echo $msg ( sleep 1 echo $msg sleep 1 echo "quit" )| telnet ${REMOTE_IP} ${REMOTE_PORT}>./log/telnet_wls.log fi echo `date +%H\:%M\‘%S\"` "脚本CORE_EXEC.sh结束...通道:"$1",单次捞取数量:"$2
原文地址:https://www.cnblogs.com/cac2020/p/11577253.html
时间: 2024-11-08 02:25:31