#---------------change history----------------------------- # nucca@20160815: initial release # #---------------release note------------------------------- #For user: # This script invokes dump_route_info.cmd to get route # information repeatedly. The oldest logs will be deleted # when log amount limit is reached # #For developer: # 1. use dos2unix to remove newline before release # #---------------definition--------------------------------- # LOG_INTERVAL=5 LOG_LIMIT=300 LOG_PATH=/sdcard/htclog LOG_PREFIX=RouteInfo #---------------redirect temporary folder------------------ # dump_route_info.cmd need access temporary folder but it # may not have permission to create temporary file on # default temporary folder /data/local/ # # workaround: redirect temporary folder to /sdcard # export TMPDIR=/sdcard #---------------main--------------------------------------- # main script entry # # Function : main # Input : (none) # Output : (none) # function main(){ while true do dump_route_info rotate_log_files sleep $LOG_INTERVAL done } #---------------dump routing information------------------- # Invoke "dump_route_info.cmd" to dump routing information # # Function : dump_route_info # Input : (none) # Output : (none) # function dump_route_info(){ current_date=`date +%Y%m%d_%H%M%S` dump_route_info.cmd mkdir -p $LOG_PATH cp /sdcard/RouteInfo.txt $LOG_PATH/${LOG_PREFIX}_$current_date.txt } #---------------count log amount--------------------------- # because android doesn't have command "wc", the following line # can't be invoked # log count: $(find ./ -maxdepth 1 -name "${LOG_PREFIX}*.txt" | wc -l) # # workaround: count file amount manually by loop # # Function : count_log_amount # Input : (none) # Output : $RET: current log amount # function count_log_amount(){ RET=0 for name in $(ls $LOG_PATH | grep $LOG_PREFIX) do echo "file #${RET}: $name" RET=$(( $RET + 1 )) done } #---------------rotate log files--------------------------- # when log amount limit ($LOG_LIMIT) is reached, the oldest # log file is deleted # # Function : rotate_log_files # Input : (none) # Output : (none) # function rotate_log_files(){ count_log_amount local log_count=${RET} echo "log count: $log_count" if [ $log_count -gt $LOG_LIMIT ]; then echo "deleting the oldest logs because file amount is more than $LOG_LIMIT .." ls $LOG_PATH/${LOG_PREFIX}*.txt -t | sed -e "1,${LOG_LIMIT}d" | xargs rm -rf else echo "less than file limit $LOG_LIMIT" fi } #---------------main entry--------------------------------- # main $* exit