当前位置:文档之家› 启动程序脚本

启动程序脚本

speed13:devis:104: cat switch.sh
#!/bin/sh
if [ $# -ne 2 -o `echo $1 |awk '{print length($1)}' ` -ne 6 ] 脚本使用参数说明以及例子
then
echo "`basename $0` : billperiod hostid "
echo "`basename $0` : 200109 r11 "
exit
fi
homedir=`pwd`
billperiod=$1
hostid=$2
shortperiod=`echo $billperiod |cut -c3-6`

logdir=${homedir}/_log 日志目录
notedir=${logdir}/_$shortperiod
lockdir=${homedir}/_lock
for adir in $logdir $notedir ${lockdir}
do
if [ ! -d ${adir} ]
then
mkdir ${adir}
fi
done
lockfile=${lockdir}/`basename $0`.${billperiod}.lock ..lock和 .run 锁目录文件,确保程序只能启动一次
runfile=${lockdir}/`basename $0`.${billperiod}.run
excpara=${homedir}/exec.cfg
if [ -f ${lockfile} ]
then
echo "Another running.exit."
exit
fi
if [ ! -f ${excpara} ]
then
echo "not excpara"
exit
fi
touch ${lockfile}
touch ${runfile}
trap 'test -f ${lockfile} && rm ${lockfile};test -f ${runfile} && rm ${runfile};exit 1' 2 9 15

sys=`expr 2 - ${shortperiod} % 2`

logfile=${logdir}/`basename $0`.${billperiod}.log
if [ ! -f ${logfile} ]
then
touch ${logfile}
fi

#---user GapFile to control the sleep time between each task cycle---
attemperfile=$homedir/attempercfg.$hostid
GapFile=$homedir/GapFile
if [ ! -f ${GapFile} ]
then
echo "GapFile is not there!exit"
exit
fi

while [ -f ${runfile} ]
do

grep -v '#' $attemperfile |while read line
do
parafile=${homedir}/`echo $line |awk '{print $1}' `
destroot=`echo $line |awk '{print $2}' |sed "s/@/${sys}/g" `

cat ${parafile} | grep -v "#" | sed "s/yymm/${shortperiod}/g" | sed "s/@/${sys}/g" | while read line

do

if [ ! -f ${runfile} ]
then
continue
fi

type=`echo ${line} | awk '{print $1}'`
rootdir=`echo ${line} | awk '{print $2}'`
source=`echo ${line} | awk '{print $3}'`
sourcedir=${rootdir}/${source}
dupdir=${rootdir}/swtdup
errordir=${rootdir}/errlink
notefile=$notedir/${type}.log

for dirs in ${errordir} ${dupdir}
do
if [ ! -d ${dirs} ]
then
mkdir -p ${dirs}
fi
done

errfilenum=`ls ${errordir} | wc -l | awk '{print $1}'`
if [ ${errfilenum} -ne 0 ]
then
echo ${errordir}" have some error files !" | mail devis
fi

for code in `cat ${excpara}`
do
destdir=${destroot}/${code}/cdrlink2
workdir=${destroot}/${code}/cdrwork
backdir=${destroot}/${code}/cdrlink1
for dirs in ${destdir} ${workdir} ${backdir}
do

if [ ! -d ${dirs} ]
then
mkdir -p ${dirs}
fi
done
done
${homedir}/switch_split ${sourcedir} ${destroot} cdrlink1 cdrwork ${billperiod} ${notefile} ${dupdir} cdrlink2 ${errordir} >> ${logfile} 2>&1
sleep 3
done

done
GapTime=`cat $GapFile`
sleep $GapTime

done
test -f ${lockfile} && rm ${lockfile}
test -f ${runfile} && rm ${runfile}


相关主题
文本预览
相关文档 最新文档