How to automatically turn off your laptop when battery status is displayed in Linux


Automatically Shutting Down Your Laptop at Low Battery Levels

Maintaining long battery life and protecting data are crucial for laptop users. In this article, we’ll show you how to create a simple Bash script that automatically shuts down your laptop when the battery level falls below 20%. Additionally, you’ll learn how to set up a crontab to run the script every 10 minutes, ensuring continuous monitoring.

Creating a Bash Script

The Bash script we have prepared will check the current battery level and compare it to a set minimum threshold. If the battery level drops below this threshold, the script initiates a system shutdown, helping to protect your data and hardware.

Also you can download script:

Don’t forget to grant permissions to run it:

Crontab Configuration

Crontab is a tool that allows you to schedule tasks in the Linux system. With it, we can set up regular battery checks.

Summary

With this setup, you can rest assured about the condition of your laptop even during intensive use. Automatic shutdown at low battery levels not only protects the equipment but also helps maintain a longer battery life.