leng_feng_jing 2017-02-01 02:56 采纳率: 50%
浏览 1638
已采纳

Linux下如何在程序中关机

买了树莓派为了防止板子温度过高,想写个开机自启程序,当CPU温度超过85℃时自动关机

  • 写回答

2条回答

  • 战在春秋 2017-02-01 08:33
    关注

    在论坛上找到一个范例,希望有帮助:

    #!/bin/sh
    #  This script reads the Broadcom SoC temperature value and shuts down if it 
    #  exceeds a particular value.
    #  80ºC is the maximum allowed for a Raspberry Pi.
    
    # Get the reading from the sensor and strip the non-number parts
    SENSOR="`/opt/vc/bin/vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1`"
    # -gt only deals with whole numbers, so round it.
    TEMP="`/usr/bin/printf "%.0f\n" ${SENSOR}`"
    # How hot will we allow the SoC to get?
    MAX="78"
    
    if [ "${TEMP}" -gt "${MAX}" ] ; then
     # This will be mailed to root if called from cron
     echo "${TEMP}ºC is too hot!"
     # Send a message to syslog
     /usr/bin/logger "Shutting down due to SoC temp ${TEMP}."
     # Halt the box
     /sbin/shutdown -h now
     else
      exit 0
    fi
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题