#!/bin/sh LOG_NAME="messages" echo ' ' > $LOG_NAME function loop_clean_log(){ #LOG_NAME="PaasMainApp_*.log" BASE_DIR=`dirname $0` && cd $BASE_DIR USELESS_LOG_FILE=`find . -name "${LOG_NAME}-*" -type f -mtime +1` LOG_FILE=${BASE_DIR}/messages_clean.log cp ${LOG_NAME} ${LOG_NAME}-`date +%F-%T` echo ' ' > ${LOG_NAME} echo "dir name is: "`pwd` echo "useless log file: "$USELESS_LOG_FILE rm -f ${USELESS_LOG_FILE} 2>&1 if [ $? -eq 0 ] then echo `date`==="日誌清理成功" >> ${LOG_FILE} echo ${USELESS_LOG_FILE} >> ${LOG_FILE} else echo `date`==="日誌清理失敗" >> ${LOG_FILE} fi } while [ 1 ] do loop_clean_log sleep 12h done