嵌入式学习笔记-记录系统启动次数

本文介绍两种计算开发板启动次数的方法。一种是通过创建并计数.log文件的数量,另一种是记录启动时间到/runcount.log中,通过行数确定启动次数。

在实际应用的过程中,我偶尔会用到计算开发板的启动次数,最笨的方法将所有log保存,最后就是查看log,数一下启动次数,可以通过查找关键字的方式(当然,我不会笨到启动一次记录一次的,嘿嘿)。感觉这样太麻烦了,现在都啥时代了,还这样做。

 

准备工作,首先要找到你系统启动后自动运行的脚本,我的板子是/autorun.sh ,这样做的原因是,在你没看到或者不小心启动了或者复位了也能监测到,你如果要求手动运行监测脚本,那么这种歌情况就不能记录了。让后将下面的脚本拷贝到这个自启动脚本。后来就写了这个脚本

脚本1:

root@fetmx6ull-s:/root# cat /autorun.sh 
#!/bin/bash 

# first mode ,calc the count of file ,
runcount=1
for i in `find /root/ -name "*.log"`
do	
	runcount=`expr ${runcount} + 1`
done
echo "system is run ${runcount} counts"
echo "power on" >> /root/${runcount}.log 
sleep 1s

执行如下:

root@fetmx6ull-s:/root# rm *        
root@fetmx6ull-s:/root# /autorun.sh 
system is run 1 counts
root@fetmx6ull-s:/root# /autorun.sh 
system is run 2 counts
root@fetmx6ull-s:/root# /autorun.sh 
system is run 3 counts
root@fetmx6ull-s:/root# /autorun.sh 
system is run 4 counts
root@fetmx6ull-s:/root# /autorun.sh 
system is run 5 counts
root@fetmx6ull-s:/root# ls
1.log  2.log  3.log  4.log  5.log
root@fetmx6ull-s:/root# 

脚本2:

上面的脚本是通过每次启动建立一个文档,通过计算文档个数来完成,这个有几个不好的地方,如当其他脚本也不小心生成了  。log 文件,就会导致计算错误,或者当启动次数多了,文件都比较多,查找看着乱,那么就产生了第二个脚本;

这个脚本是通过查看 /runcount.log中的行数来判断当前启动了多少次,每启动一次i增加一行,并且把启动时间进行记录,注意,时间必须在开发板有电池的情况才是可以的,否则时间不能作为参考项。 

执行如下:

root@fetmx6ull-s:/root# /autorun.sh 
cat: can't open '/root/runcount.log': No such file or directory
18:49:02:  power is run 1 counts
root@fetmx6ull-s:/root# /autorun.sh 
18:49:10:  power is run 2 counts
root@fetmx6ull-s:/root# /autorun.sh 
18:49:12:  power is run 3 counts
root@fetmx6ull-s:/root# /autorun.sh 
18:49:14:  power is run 4 counts
root@fetmx6ull-s:/root# /autorun.sh 
18:49:16:  power is run 5 counts
root@fetmx6ull-s:/root# ls
runcount.log
root@fetmx6ull-s:/root# cat runcount.log 
18:49:02: power is run 1 counts
18:49:10: power is run 2 counts
18:49:12: power is run 3 counts
18:49:14: power is run 4 counts
18:49:16: power is run 5 counts

怎么样,又可以偷懒了吧?嘿嘿。

要相信  ,懒人推动社会进步。。。。。。

喜欢吗,关注并留言吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

six2me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值