Thursday, May 31, 2018

Sending notifications alert to the User if battery status getting less than a threshold and shutdown the pc using shell script,Linux Teacher Sourav,Kolkata 09748184075

#!/bin/bash
#01/06/2018


while true
do
    battery_level=`acpi -b | acpi -b | cut -f4 -d ' '|tr -d ',%'`
    if [ $battery_level -le 5 ]; then
       notify-send "Battery is less than 5%!" "Charging: ${battery_level}%" " Please connect the charger ,the system will shutdown after 2 minute"
shutdown -P +2 "Shutdown script started"
  
    elif [ $battery_level -le 20 ]; then
       notify-send "Battery is lower than 20%!" "Please connect the charger: ${battery_level}%"
      

 

    fi

    sleep 10 # run this script in every 10 seconds
done


Source:https://askubuntu.com/questions/518928/how-to-write-a-script-to-listen-to-battery-status-and-alert-me-when-its-above?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

No comments:

Post a Comment