Useful Scripts for Linux

Discussion in 'Linux' started by KaptainBug, Jun 9, 2014.

  1. KaptainBug

    KaptainBug Member

    Creating this thread to share useful scripts for Linux.

    Script #1: To monitor battery and display notification and play a sound

    Linux distro already have low battery notification, but when watching movies in youtube or doing other tasks in full screen it does not display a notification. I got annoyed when I did not get any notification and the laptop shut down itself when it reached critical battery. So I wrote this script.

    How to use: Download the attached file and rename it to

    Right click the file and click properties. Select permissions tab and check 'Allow executing the file as program'.
    Open startup applications and add the script to startup. Restart the machine and you are done. Now you will get a pop-up notification and sound when battery is low and when charging is complete. Also when the battery reaches 5%, system will shut down.

    This script is written for Linux Mint 17. So all the icons, battery path and sound will work fine in Linux Mint 17. You can change few parameters as per your distro and use this script.

    Let me know if you have any suggestions to improve the script.



    # low battery in %

    # critical battery in % (execute action)

    # action

    # sleep 5 mins

    # display icon

    # path to battery /sys

    # notify sound
    PLAY="aplay /usr/share/sounds/linuxmint-gdm.wav"

    while [ true ]; do
    if [ -e "$BATTERY_PATH" ]; then
    BATTERY_ON=$(cat $BATTERY_PATH/status)

    if [ "$BATTERY_ON" == "Discharging" ]; then

    if [ "$CURRENT_BATTERY" -lt "$CRITICAL_BATTERY" ]; then
    notify-send -i "$CRITBAT_ICON" "Battery is Critical - $CURRENT_BATTERY%. Shutting down in 60 sec."
    sleep 60

    elif [ "$CURRENT_BATTERY" -lt "$LOW_BATTERY" ]; then
    notify-send -i "$LOWBAT_ICON" "Battery is Low - $CURRENT_BATTERY%."

    elif [ "$BATTERY_ON" == "Full" ]; then
    notify-send -i "$FULLBAT_ICON" "Battery is Full - 100%."
    sleep $SLEEP

    Attached Files:

  2. Google Adsense

  3. Bala

    Bala Administrator Staff Member

    Thanks captain bug, but the Mate desktop environment already has an applet for this I suppose but never the less it is a good addition for Cinnamon users.
  4. illumination

    illumination Guest

    It is good all the way around, because things that function properly on your system, may not on others.. Posting found work arounds and solutions will be a great addition to any Linux section.. :)

Share This Page