嵌入式系统老化检测rtc

Just_Esme

关注

阅读 52

2022-03-14

我们可以使用hwclock检测rtc功能是否正常,不说了,直接上脚本

root@forlinx:~# cat testrtc.sh 
#!/bin/bash

while true
do
	echo "***test rtc starting***"
	rtctime=`date +"%Y-%m-%d %H:%M:%S"`
	date -s "$rtctime"
	hwclock -w
	[ $? -eq 0 ] && echo "`date +%T` hwclock -w success" || echo "`date +%T` hwclock -w failure"
	hwclock -r
	[ $? -eq 0 ] && echo "`date +%T` hwclock -r success" || echo "`date +%T` hwclock -r failure"
	sleep 10s
	echo ""
done

执行脚本如下:

root@forlinx:~# ./testrtc.sh 
***test rtc starting***
Thu Mar  3 11:55:22 CST 2022
11:55:22 hwclock -w success
2022-03-03 11:55:22.686207+0800
11:55:22 hwclock -r success

***test rtc starting***
Thu Mar  3 11:55:32 CST 2022
11:55:32 hwclock -w success
2022-03-03 11:55:32.528817+0800
11:55:32 hwclock -r success

这样每10s就检测一次;

精彩评论(0)

0 0 举报