shell判斷批處理的目錄下的流文件是否處理完成
log_error() {
? ? echo -e $target date "+%Y-%m-%d %H:%M:%S"
["\033[31merror\033[0m"] : $@
? ? echo -e $target date "+%Y-%m-%d %H:%M:%S"
["\033[31merror\033[0m"] : $@ >> $LOG_FILE
}
log() {
? ? echo -e $target date "+%Y-%m-%d %H:%M:%S"
: $@
? ? echo -e $target date "+%Y-%m-%d %H:%M:%S"
}
BASE_DIR=/home/iflytek/invoice
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
LOG_FILE=$SCRIPTPATH/runscript.log
DIR6_START_CONF=$SCRIPTPATH/dir6_start.conf
DIR6_RUN_CONF=$SCRIPTPATH/dir6_run.conf
DIR6_STOP_CONF=$SCRIPTPATH/dir6_stop.conf
DIR8_START_CONF=$SCRIPTPATH/dir8_start.conf
DIR8_STOP_CONF=$SCRIPTPATH/dir8_stop.conf
OUT_DIR=/home/iflytek/out
IN_DIR=/home/iflytek/in
RESULT_DIR=/home/iflytek/result;
LOCK_FILE=$SCRIPTPATH/script.lock
DONE_FILE=$SCRIPTPATH/script.done
#$(cat $DIR6_START_CONF);
#$(cat $DIR8_START_CONF);
#is_lock?
if [ -f $LOCK_FILE ]; then
exit
else
? ?touch $LOCK_FILE
fi
if [ ! -f $LOG_FILE ]; then
touch $LOG_FILE;
fi
if [ ! -f $DIR6_START_CONF -o ! -f $DIR6_STOP_CONF? -o ! -f $DIR8_START_CONF -o? ! -f $DIR8_STOP_CONF ]; then
rm -rf $LOCK_FILE
exit
fi
if [ ! -f? $DIR6_RUN_CONF? ]; then
echo $(cat $DIR6_START_CONF) > $DIR6_RUN_CONF
fi
if [ ! -f? $DIR8_RUN_CONF? ]; then
echo $(cat $DIR8_START_CONF) > $DIR8_RUN_CONF
fi
if [ ! -d $RESULT_DIR ]; then
? ? mkdir -p $RESULT_DIR
fi
function diradd(){
if [ $(cat $DIR8_RUN_CONF) -gt $(cat $DIR8_STOP_CONF) ] ; then
? ? ? ? ? ? ? ? ? ? ? ? echo $(cat $DIR8_START_CONF) > $DIR8_RUN_CONF;
? ? ? ? ? ? ? ? ? ? ? ? echo $(($(cat $DIR6_RUN_CONF)+1)) > $DIR6_RUN_CONF;
rm -rf $LOCK_FILE
exit
fi
if [ $(cat $DIR6_RUN_CONF) -gt $(cat $DIR6_STOP_CONF) ] ; then
? ? ? ? ? ? ? ? ? rm -rf $LOCK_FILE
? ? ? ? ? ? ? ? ? ? ? ? ?exit
fi
if [ ! -d $BASE_DIR/$(cat $DIR6_RUN_CONF)/$(cat $DIR8_RUN_CONF) ]; then
? ? echo $(($(cat $DIR8_RUN_CONF)+1)) > $DIR8_RUN_CONF;
diradd
else
DIR_6="$(cat $DIR6_RUN_CONF)"
DIR_8="$(cat $DIR8_RUN_CONF)"
#cleaning rubish
tran_process_num=0
for one in $OUT_DIR/*
do
filename=${one##*/}
if [ -f $one/f.tran.new ] && [ ! -f $one/f.tran.done ]; then
tran_process_num=$[$tran_process_num+1]
elif [ -f $one/f.tran.done ]; then
tar -zcf $RESULT_DIR/$filename.tgz $one/*.txt
rm -rf $one
log already tran done, generate the file:$RESULT_DIR/$filename.tgz, delete unused record file:$one!
fi
done
parse_process_num=0
for one in $IN_DIR/*
do
if [ -f $one/f.parse.new ] && [ ! -f $one/f.parse.done ]; then
parse_process_num=$[$parse_process_num+1]
elif [ -f $one/f.parse.done ]; then
log already parse done, delete!
rm -rf $one
fi
done
cd $IN_DIR;
NUM=$((`ls -l |grep "^d"|wc -l`))
if [ $NUM gt 4 ]; then
rm -rf $LOCK_FILE
exit
fi
cd $OUT_DIR;
NUM=$((`ls -l |grep "^d"|wc -l`))
if [ $NUM gt 4 ]; then
rm -rf $LOCK_FILE
exit
fi
#iterate
mkdir $IN_DIR/${DIR_6}_${DIR_8}
for dir_4 in? $BASE_DIR/${DIR_6}/${DIR_8}/*
do? ? ??
? ? ? ? cp $dir_4/*.wav $IN_DIR/${DIR6}${DIR_8}
done
echo -e -n "version=taiping_ds" > $IN_DIR/${DIR_6}_${DIR_8}/f.parse.new.tmp
mv $IN_DIR/${DIR_6}_${DIR_8}/f.parse.new.tmp $IN_DIR/${DIR_6}_${DIR_8}/f.parse.new
end_time=`date ‘+%s‘`
echo ${DIR_6}_${DIR_8} >? $DONE_FILE
echo $(($(cat $DIR8_RUN_CONF)+1)) > $DIR8_RUN_CONF
rm -rf $LOCK_FILE
exit
fi
}
diradd
shell判斷批處理的目錄下的流文件是否處理完成