<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archiwa Battery - soban</title>
	<atom:link href="https://soban.pl/category/battery-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://soban.pl/category/battery-en/</link>
	<description>IT, Linux, Servers, Security</description>
	<lastBuildDate>Fri, 24 Jan 2025 10:46:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>How to automatically turn off your laptop when battery status is displayed in Linux</title>
		<link>https://soban.pl/how-to-automatically-turn-off-your-laptop-when-battery-status-is-displayed-in-linux/</link>
		
		<dc:creator><![CDATA[soban]]></dc:creator>
		<pubDate>Fri, 24 Jan 2025 10:30:58 +0000</pubDate>
				<category><![CDATA[Battery]]></category>
		<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">https://soban.pl/?p=546</guid>

					<description><![CDATA[<p>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&#8217;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&#8217;ll learn how to set up a [&#8230;]</p>
<p>Artykuł <a href="https://soban.pl/how-to-automatically-turn-off-your-laptop-when-battery-status-is-displayed-in-linux/">How to automatically turn off your laptop when battery status is displayed in Linux</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="1019" height="1024" src="https://soban.pl/wp-content/uploads/2025/01/image-1-1019x1024.png" alt="" class="wp-image-547" style="width:619px;height:auto" srcset="https://soban.pl/wp-content/uploads/2025/01/image-1-1019x1024.png 1019w, https://soban.pl/wp-content/uploads/2025/01/image-1-298x300.png 298w, https://soban.pl/wp-content/uploads/2025/01/image-1-150x150.png 150w, https://soban.pl/wp-content/uploads/2025/01/image-1-768x772.png 768w, https://soban.pl/wp-content/uploads/2025/01/image-1.png 1122w" sizes="(max-width: 1019px) 100vw, 1019px" /></figure>



<p><br>Automatically Shutting Down Your Laptop at Low Battery Levels</p>



<p>Maintaining long battery life and protecting data are crucial for laptop users. In this article, we&#8217;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&#8217;ll learn how to set up a crontab to run the script every 10 minutes, ensuring continuous monitoring.</p>



<h3 class="wp-block-heading">Creating a Bash Script</h3>



<p>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.</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">#!/bin/bash

# Define the minimum battery level before shutdown
MIN_BATTERY_LEVEL=20

# Get the current battery level
current_level=$(cat /sys/class/power_supply/BAT0/capacity)

# Check if the current battery level is less than or equal to the minimum level
if [[ "$current_level" -le "$MIN_BATTERY_LEVEL" ]]; then
  echo "Battery level is $current_level%, which is below the threshold of $MIN_BATTERY_LEVEL%. Shutting down..."
  # Shutdown command
  /sbin/shutdown -h now
else
  echo "Battery level is $current_level%, no need to shut down."
fi</pre></div>



<p>Also you can download script:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">wget https://soban.pl/bash/check_battery.sh</pre></div>



<p>Don&#8217;t forget to grant permissions to run it:</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">chmod +x check_battery.sh</pre></div>



<h3 class="wp-block-heading">Crontab Configuration</h3>



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



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">crontab -e

# Add the following line to crontab to run the script every 10 minutes
*/10 * * * * /root/check_battery.sh &gt; /dev/null 2&gt;&amp;1</pre></div>



<h3 class="wp-block-heading">Summary</h3>



<p>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.</p>
<p>Artykuł <a href="https://soban.pl/how-to-automatically-turn-off-your-laptop-when-battery-status-is-displayed-in-linux/">How to automatically turn off your laptop when battery status is displayed in Linux</a> pochodzi z serwisu <a href="https://soban.pl">soban</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
