summaryrefstree
path: root/usr/bin/kernellog_output.sh
blob: acb20902df2e4e5fd6e496f9d2e40edc1409bcd7 (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
#!/usr/bin/sh


mkdir -p /var/log/Kernellog/
chmod 777 /var/log/Kernellog/
#chown system:system /data/klog

#mkdir -p /var/log/Kernellog/
#chmod 777 /var/log/Kernellog/
bootcount=`ls /var/log/Kernellog | busybox sort | busybox tail -1`

if [ ${bootcount} -eq 999 ]; then
    bootcount=1
    DIR_Maxcounter=0
    rm -rf /var/log/Kernellog/*
else

   bootcount=`expr $bootcount + 1`
fi

DIR_Maxcounter=0
if [ ${bootcount} -gt ${DIR_Maxcounter} ]; then
    DIR_Maxcounter=${bootcount}
fi

DIR_ID=`busybox printf %03d ${DIR_Maxcounter}`

LOG_DIR=/var/log/Kernellog/${DIR_ID}
#LOG_DIR_error=/var/log/Kernellog/${DIR_ID}
# dmesg > ${LOG_DIR}/kmsg
if [ -f /proc/kmsg ]
then
    mkdir -p ${LOG_DIR}
    chmod 777 ${LOG_DIR}
#    chown system:system ${LOG_DIR}

    cat /proc/kmsg > ${LOG_DIR}/Kernellog-Info${DIR_ID}.log
	
	#1. 脚本停在cat位置
	#2. 修正方式 添加&
		#cat /proc/kmsg > ${LOG_DIR}/Kernellog-Info${DIR_ID}.log &
	#3. 未修改原因:当前现状可接受
    chmod 666 ${LOG_DIR}/*
#    chown system:system ${LOG_DIR}/*
else
    echo "NO last_kmsg"
fi

#循环删除文件,只保留200个
#if [ ${DIR_Maxcounter} -gt 200 ];then
#    DIR_Maxcounter=`expr ${DIR_Maxcounter} - 200`
#    for Dir in `ls /var/log/Kernellog/`
#   do
#   DIR_ID=`busybox printf %03d ${DIR_Maxcounter}`
#       if [ ${Dir} -lt ${DIR_ID} ];then
#	           rm -rf /var/log/Kernellog/${Dir}
#          sync
#       fi
#   done
#else
#    echo "DO Nothing"
#fi