一、如何执行
./adapter.sh 20211121 'importdata.sh|!DATE'
adapter.sh:适配器脚本
20201121:适配器脚本参数1,执行日期
'importdata.sh|!DATE':适配器脚本参数2,具体需要执行的脚本和参数,以|分隔,多个参数也以|分隔
二、有啥好处
为了练手。。。或者说在某些情况下调用方便,无论多少个参数拼接|就行了,在适配器脚本中调用解析执行即可。
三、具体脚本
#!/bin/bash if [ $# -lt 2 ] || [ $1 = "" ] || [ $2 = "" ] then echo "传入参数不符合要求" exit 1 fi JOB_DATE=$1 JOB_PARA_LIST=$2 YEAR=`echo $JOB_DATE|cut -c 1-4` MONTH=`echo $JOB_DATE|cut -c 5-6` DAY=`echo $JOB_DATE|cut -c 7-8` DATE=`date '+%Y%m%d'` DATE4=`echo $DATE|cut -c 1-4` DATE6=`echo $DATE|cut -c 1-6` DATE8=$DATE CMD=`echo $JOB_PARA_LIST|sed 's/|/ /g'|sed 's/\!DATE4/'${DATE4}'/g'|sed 's/\!DATE6/'${DATE6}'/g'|sed 's/\!DATE8/'${DATE8}'/g'|sed 's/\!DATE/'${DATE8}'/g'` JOB_PRG=`echo $CMD|awk '{print $1}'` ADAPTER_LOGFILE=/usr/local/myroom/script/log/adapter_${JOB_DATE}.log JOBPRG_LOGPATH=/usr/local/myroom/script/log/$DATE6 JOBPRG_LOGFILE=${JOBPRG_LOGPATH}/${JOB_PRG}${DATE8}.log SHPATH=/usr/local/myroom/script echo "适配器调用脚本命令: "$CMD 2>&1|tee -a ${ADAPTER_LOGFILE} it=1 while [ ${it} -lt 100 ] do if [ ! -d ${JOBPRG_LOGPATH} ] then mkdir -p ${JOBPRG_LOGPATH} retcode=$? if [ $retcode -eq 0 ] then echo "adapter第"${it}"次创建日期目录成功:" 2>&1|tee -a ${ADAPTER_LOGFILE} break else echo "adapter第"${it}"次创建日期目录失败:" 2>&1|tee -a ${ADAPTER_LOGFILE} it=`expr ${it} + 1` sleep 1 fi else break fi done if [ ${it} -ge 100 ] then echo "adapter第"${it}"次创建日期目录失败:" 2>&1|tee -a ${ADAPTER_LOGFILE} exit 1 fi echo "开始执行脚本--------"${JOB_PRG}"--------" 2>&1|tee -a ${ADAPTER_LOGFILE} ${SHPATH}/${CMD} 2>&1|tee -a ${ADAPTER_LOGFILE} echo "执行脚本完成--------"${JOB_PRG}"--------" 2>&1|tee -a ${ADAPTER_LOGFILE}