blob: 267bbb6aded85dc0b06b8bf1f278ef684c49e0cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#---------------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
|