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
1. Write a backup script rem auther:www.yumi-info...
How to modify the mysql table partitioning progra...
I logged into the backend to check the solution t...
Table of contents 1. Connect to Tencent Cloud Ser...
Normal explanation % means any client can connect...
Today, I want to write about a "low-tech&quo...
By chance, I discovered that a SQL statement prod...
In web development, you often encounter characters...
In the previous article, we learned about the pas...
Table of contents 1. Overview 2. Application Exam...
Preface The essence of deadlock is resource compe...
Only display Docker container mount directory inf...
View system help help contents mysql> help con...
Table of contents Props comparison of class compo...
When making a new version of the configuration in...