Preface The electricity in my residence has been unstable recently, and there are frequent sudden power outages. Although I have a laptop, it may not be able to receive power. If this continues, the SSD in the laptop will soon fail. So I wrote a simple script that shuts down the computer when the battery is low, and then uses crontab or systemd timers to check it regularly. For information on how to use the crontab command, please refer to: https://www.jb51.net/article/148575.htm Let’s take a look at the detailed introduction. check_shutdown.timer: $ cat /etc/systemd/system/check_shutdown.timer [Unit] Description=Check if battery is low every 10 minutes [Timer] OnCalendar=*:0/10 Persistent=true [Install] WantedBy=timers.target check_shutdown.service: $ cat /etc/systemd/system/check_shutdown.service [Service] ExecStart= ExecStart=/home/jiajun/.xmonad/scripts/shutdown.py check_shutdown.py: #!/home/jiajun/.py3k/bin/python import psutil import logging import os import datetime bat = psutil.sensors_battery() logging.warn("%s: battery status: %s", datetime.datetime.now(), bat) if bat.percent < 15: logging.warn("gonna shutdown") os.system("sudo shutdown -h now") Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Installation of mysql-community-server. 5.7.18-1.el6 under centos 6.5
>>: JavaScript implements mouse drag to adjust div size
Data backup and restore part 3, details are as fo...
Sometimes we want to execute a command in a conta...
First, install openssh-server in docker. After th...
Disclaimer: Since the project requires the use of...
You may encounter the following problems when ins...
This article example shares the specific code of ...
Table of contents 1. First, configure the main.js...
The <tbody> tag is used to define the style...
Preface The gradient of the old version of the br...
Restart all stopped Docker containers with one co...
Copy code The code is as follows: 1. Sina Weibo &...
Comprehensive understanding of html.css overflow ...
During the crawler development process, you must ...
There are three main ways of MySQL replication: S...
Table of contents 1. Scene layout 2. Add a handle...