#!/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