RK356x监控温度及CPU频率的服务(Ubuntu20.04)

1 脚本

touch /userdata/show_temps.sh

添加内容

#! /bin/bash
//压力测试
stress --cpu 4 &
stress --cpu 4 &

while true; do
    types=($(cat /sys/class/thermal/thermal_zone*/type))
    temps=($(cat /sys/class/thermal/thermal_zone*/temp))
    freqs=($(cat /sys/bus/cpu/devices/cpu*/cpufreq/cpuinfo_cur_freq))
    freqss=($(cat /sys/bus/cpu/devices/cpu*/cpufreq/scaling_cur_freq))
    govs=($(cat /sys/bus/cpu/devices/cpu*/cpufreq/scaling_governor))

    for (( i=0; i<${#types[@]}; i++ )); do
        echo "Type: ${types[$i]} - Temperature: ${temps[$i]}"
    done

    for (( i=0; i<${#freqs[@]}; i++ )); do
       echo "CPU${i}:Cpuinfo_freq ${freqs[$i]} - Scaling freq: ${freqss[$i]}"
    done

    for (( i=0; i<${#govs[@]}; i++ )); do
       echo "CPU${i}: ${govs[$i]}"
    done


echo "-------------------------"  # 添加分隔线
    sleep 1
done

2 系统服务

touch /etc/systemd/system/show_temps.service

添加内容

[Unit]
Description=Show Temps Service
After=multi-user.target

[Service]
ExecStart=/bin/bash /userdata/show_temps.sh

[Install]
WantedBy=multi-user.target

3 系统服务应用

重新加载systemd配置

sudo systemctl daemon-reload

启用并启动服务

sudo systemctl enable show_temps.service
sudo systemctl start show_temps.service

检查服务

sudo systemctl status show_temps.service

停止服务

sudo systemctl stop show_temps.service

4 日志获取

显示指定服务日志

journalctl -u show_temps.service

实时跟踪指定服务日志

journalctl -u show_temps.service -f

你可能感兴趣的:(linux,android,bash,service)