Skip to main content
 首页 » 操作系统

Linux 掉电脉冲映射串口log和dmesg到文件中的log

2022年07月19日198powertoolsteam

1.echo 1 > /mytest/boot_times

2.systemctl enable i2c_dmesg.service

root:/mytest# tree 
. 
|-- boot_times 
|-- i2c_dmesg.txt

root:/etc# cat i2c_dmesg.sh
#!/bin/sh

value=$(cat /mytest/boot_times)

# Keep dmesg file the same as console log
echo "========sfl: reboot=$value========" >> /mytest/i2c_dmesg.txt
/bin/dmesg >> /mytest/i2c_dmesg.txt
echo "========sfl: reboot=$value========" > /dev/console

let value=value+1
echo $value > /mytest/boot_times

sync

sync

root:/etc# cat /lib/systemd/system/i2c_dmesg.service  
[Unit] 
Description=dmesg for i2c oops 
After=weston.service 
 
[Service] 
ExecStart=/etc/i2c_dmesg.sh 
Type=simple 
 
[Install] 
WantedBy=multi-user.target

本文参考链接:https://www.cnblogs.com/hellokitty2/p/9735166.html