读取系统和硬件时间脚本
通过脚本1s读取一次系统时间和硬件时间,并将读取的情况记录到日志文件
#!/bin/sh
ok_count=0
fail_count=0
while true; do
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
result=$(hwclock)
echo "[$timestamp] - $result"
echo "$timestamp - $result" >> hwclocklog
# last_chars=$(echo "$result" | tail -c 8)
last_chars=$(echo "$result" | grep '+0800')
if [ -n "$last_chars" ]; then
ok_count=$((ok_count + 1))
else
fail_count=$((fail_count + 1))
fi
echo -e "\e[32mOK: $ok_count\e[0m"
echo -e "\e[31mFail: $fail_count\e[0m"
echo "OK: $ok_count, Fail: $fail_count" > hwclockstat
sleep 1
done