zoukankan      html  css  js  c++  java
  • 实现非管理型UPS在linux主机上的停电自动关机

    买了个山特的SANTAK TG-BOX 850 UPS,自带USB通讯线缆。本以为官方软件提供Linux下的CLI命令以监控UPS状态.

    官网提供的下载链接巨慢无比不说,CLI下只提供了安装脚本,没有状态监控程序。我TM……

    算了,当个非管理型的UPS用吧。搜索了下网上提供的脚本,感觉写的都不太合适。自己重新修改了一下。

    #!/bin/sh
    while true
    do
        ping -c 1 192.168.50.2 > /dev/null
        ret=$?
        if [ $ret -ne 0 ]
        then
        echo -e "AC POWER LOSS! UPS WORKING NOW!
    -------------------------------
    Save your jobs and a further check will be execute in 3 mins,if it still loss,system will be shutdown immediately!" | wall
        sleep 180
        ping -c 1 192.168.50.2 > /dev/null
        ret=$?
            if [ $ret -ne 0 ]
            then
            echo -e "AC POWER STILL LOSS! SYSTEM WILL SHUTDOWN NOW" | wall
            poweroff
            fi
        fi
    sleep 5
    done

    然后把ups.sh的功能注册成服务,方便操作:

    新建/usr/lib/systemd/system/ups.service

    [Unit]
    Description=UPS monitor and shutdown automaticlly
    After=network.target
     
    [Service]
    Type=simple
    User=root
    ExecStart=nohup /root/ups.sh &
    ExecStop=/bin/kill $MAINPID
    PrivateTmp=true
     
    [Install]
    WantedBy=multi-user.target

    启动服务:

    systemctl start ups.service

    让服务开机自动运行

    systemctl enable ups.service

    done.

  • 相关阅读:
    form表单提交json格式数据
    docker搭建jenkins
    consul搭建服务注册和
    docker创建mysql镜像
    Swagger入门
    net coer log4+ELK搭建
    log4配置
    netcore autofac依赖注入
    netcore 跨域
    netcore 读取配置文件
  • 原文地址:https://www.cnblogs.com/mrcoolfuyu/p/11568370.html
Copyright © 2011-2022 走看看