一个shell脚本 Posted on 2016-12-06 工作中有时候需要使用shell来做一些文件处理,但是在使用shell脚本之前,先确定是否使用该方案来处理,以下是我一个位上线的脚本12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061################################ 消息进程管理 ## ## Author: chenjx ## Since: 2016-12-05 ## version: 1.0 ################################OLD_DIR='/data/logs/message/msg/'NEW_DIR='/data/logs/message/newMsg/'SHELL_CMD='/bin/bash'CURRENT_DIR=`pwd`SHELL_SCRIPT="${CURRENT_DIR}/pushmsgtos3one.sh"LOG_FILE='/data/logs/message/process_log.txt'PROCESS_NUM_LIST=`ps aux|grep 'pushmsgtos3one.sh'|awk -F ' ' '{if($13){print $13}}'`DIRECTORY_SEPARATOR='/'#检查进程checkNewProcess(){ RET=1 if [ -d $1 -a -x ${SHELL_SCRIPT} ] then for CHILD_DIR in `ls $1` do if echo "${PROCESS_NUM_LIST[@]}" | grep -w ${CHILD_DIR} then RET=0 else ${SHELL_CMD} ${SHELL_SCRIPT} $1${CHILD_DIR}${DIRECTORY_SEPARATOR} & if [ $? -ne '0' ] then echo '> NEW:' ${SHELL_SCRIPT} ${CHILD_DIR} ' Error' >> ${LOG_FILE} fi fi done else echo ${OLD_DIR} ${NEW_DIR}' Check Error' >> ${LOG_FILE} fi return $RET}#兼容老版本checkOldProcess(){ RET=1 if [ -d $1 -a -x ${SHELL_SCRIPT} ] then ${SHELL_CMD} ${SHELL_SCRIPT} $1 & if [ $? -ne '0' ] then echo '> OLD:' ${SHELL_SCRIPT} ${CHILD_DIR} ' Error' >> ${LOG_FILE} fi fi return $RET}checkOldProcess ${OLD_DIR}checkNewProcess ${NEW_DIR} 只是方案进行了修改,不使用这种方式来处理,由于需要清理分支,所以记录下来!