- 论坛徽章:
- 2
|
本帖最后由 lssliu 于 2011-05-24 10:50 编辑
作了个共通shell,调用这个shell的时候给shell一个参数,然后shell去读它本身的cfg文件--这个文件就是一个普通文件。
- #sign.cfg
- #配置文件test_01_01_01功能对应的配置项
- #test_01_01_01_START
- LOGOPT=3
- #-------------------------------------------------
- # Message echo type : 1-echo , 2-no echo #
- #-------------------------------------------------
- M_TYPE=1
- #-------------------------------------------------
- # LOG Directory/FileName
- #-------------------------------------------------
- LOGDFILE=${LOGDIR}/STATION_01_GPN.`date +"%Y%m%d"`.log
- #===============================================================================
- # Configuration parameters that defines job function.
- #===============================================================================
- PARAMETER_FILE=${INDIR}/work/AN06205/Status.txt
- StatusFile=`head -1 ${PARAMETER_FILE}`
- APPL_CONFIG_PARAM=$StatusFile -DLOG_FILENAME=${LOGDFILE}
- #test_01_01_01_END
复制代码
- test.sh
- #!/bin/sh -x
-
- #设定环境变量
- CURRDIR=`pwd`; cd ../..
- ENVDIR=`pwd`; export ENVDIR
- SYSCATE=`basename ${ENVDIR}`; export ENVDIR
- cd $CURRDIR
- BINDIR=${ENVDIR}/run/bin; export BINDIR
- INDIR=${ENVDIR}/run/data/in; export INDIR
- LOGDIR=${ENVDIR}/run/log; export LOGDIR
- #得到配置项在配置文件中的开始行
- StartLine=`grep -n "${1}_START" sign.cfg | awk -F: '{print $1}'`
- #得到配置项在配置文件中的结束行
- EndLine=`grep -n "${1}_END" sign.cfg | awk -F: '{print $1}'`
- STEPMSG="${1} start at ${StartLine} line, end at ${EndLine} line of ${1} sign.cfg"; export STEPMSG
- echo "sed -n '${StartLine},${EndLine}'p sign.cfg"
- #取得开始行和结束行之间的内容,去掉空行和注释行
- the_input=`sed -n "${StartLine},${EndLine}"p sign.cfg | grep -v '^#'|sed /^$/d`
- while read firstvar
- do
- tmp=$firstvar
- echo ${tmp}---------
-
- #将变量设置成环境变量
- export "${tmp}"
- secondvar=$firstvar
- done <<EOF
- $the_input
- EOF
- #test 输出环境变量
- echo ${INDIR}
- echo ${LOGOPT}
- echo ${M_TYPE}
- echo ${LOGDFILE}
- echo ${PARAMETER_FILE}
- echo ${StatusFile}
- echo ${APPL_CONFIG_PARAM}
复制代码 我执行这个共通的时候结果:-
- sh test.sh test_01_01_01
- sed -n '1,21'p sign.cfg
- LOGOPT=3---------
- M_TYPE=1---------
- LOGDFILE=${LOGDIR}/STATION_01_GPN.`date +"%Y%m%d"`.log---------
- PARAMETER_FILE=${INDIR}/work/AN06205/Status.txt---------
- StatusFile=`head -1 ${PARAMETER_FILE}`---------
- APPL_CONFIG_PARAM=$StatusFile -DLOG_FILENAME=${LOGDFILE}---------
- /work1/pgs201/JobGen-Exe/jobexe/run/data/in
- 3
- 1
- ${LOGDIR}/STATION_01_GPN.`date +"%Y%m%d"`.log
- ${INDIR}/work/AN06205/Status.txt
- `head -1 ${PARAMETER_FILE}`
- $StatusFile -DLOG_FILENAME=${LOGDFILE}
复制代码 从文件中读取的变量中的环境变量和函数没有被替换掉。
echo ${LOGOPT} 3
echo ${M_TYPE} 1
echo ${LOGDFILE} ${LOGDIR}/STATION_01_GPN.`date +"%Y%m%d"`.log
echo ${PARAMETER_FILE} ${INDIR}/work/AN06205/Status.txt
echo ${StatusFile} `head -1 ${PARAMETER_FILE}`
echo ${APPL_CONFIG_PARAM} $StatusFile -DLOG_FILENAME=${LOGDFILE}
这个有什么方法可以实现? |
|