4 edited title
| link

Please help me to debug this Debugging notify-send battery alert script

3 include information provided in answer comment
source | link

I used crontab -e to define the following:

*/5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh

The contents of the script are:

#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%"
elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]]
    then
    notify-send "Battery very low warning"  "
Battery level is ${battery_level}%
Use ac power now,
 or shutdown is imminent - close applications"
else [[ "$battery_level" -le "5" ]]
    # our custom actions for critical battery level
    notify-send "Battery critical warning"  "
Battery level is ${battery_level}%
Shutting system down now"
fi

Some statements, such as the first -le "80" are just for test/debug purposes. The problem with this script is that it results in a pop-up every 5 minutes reporting the last condition: "Battery critical warning...Shutting system down now".

Battery critical warning
Battery level is 100%
Shutting system down now

I used crontab -e to define the following:

*/5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh

The contents of the script are:

#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%"
elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]]
    then
    notify-send "Battery very low warning"  "
Battery level is ${battery_level}%
Use ac power now,
 or shutdown is imminent - close applications"
else [[ "$battery_level" -le "5" ]]
    # our custom actions for critical battery level
    notify-send "Battery critical warning"  "
Battery level is ${battery_level}%
Shutting system down now"
fi

Some statements, such as the first -le "80" are just for test/debug purposes. The problem with this script is that it results in a pop-up every 5 minutes reporting the last condition: "Battery critical warning...Shutting system down now".

I used crontab -e to define the following:

*/5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh

The contents of the script are:

#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%"
elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]]
    then
    notify-send "Battery very low warning"  "
Battery level is ${battery_level}%
Use ac power now,
 or shutdown is imminent - close applications"
else [[ "$battery_level" -le "5" ]]
    # our custom actions for critical battery level
    notify-send "Battery critical warning"  "
Battery level is ${battery_level}%
Shutting system down now"
fi

Some statements, such as the first -le "80" are just for test/debug purposes. The problem with this script is that it results in a pop-up every 5 minutes reporting the last condition:

Battery critical warning
Battery level is 100%
Shutting system down now

2 clean up formatting and english
source | link

I put on crontab withused crontab -e to define the follow action */5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh this alertfollowing:

*/5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh

The contents of the script are:


#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%" elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]] then notify-send "Battery very low warning" "
Battery level is ${battery_level}%
Use ac power now,
or shutdown is imminent - close applications
" else [[ "$battery_level" -le "5" ]] # our custom actions for critical battery level notify-send "Battery critical warning" "
Battery level is ${battery_level}%
Shutting system down now
" fi #!/bin/bash # Battery level warning script battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'` if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]] then notify-send "Battery low warning" " Battery level is ${battery_level}%" elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]] then notify-send "Battery very low warning" " Battery level is ${battery_level}% Use ac power now, or shutdown is imminent - close applications" else [[ "$battery_level" -le "5" ]] # our custom actions for critical battery level notify-send "Battery critical warning" " Battery level is ${battery_level}% Shutting system down now" fi

Actually someSome statements, such as the first -le "80" are just for test/debug purposepurposes. The problem with this script is the absolute_not_respect of conditionals statements withthat it results in a pop-up every 5 minutes reporting the last condition: "Battery critical warning...Shutting system down now""Battery critical warning...Shutting system down now".

I put on crontab with crontab -e the follow action */5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh this alert script:


#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%" elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]] then notify-send "Battery very low warning" "
Battery level is ${battery_level}%
Use ac power now,
or shutdown is imminent - close applications
" else [[ "$battery_level" -le "5" ]] # our custom actions for critical battery level notify-send "Battery critical warning" "
Battery level is ${battery_level}%
Shutting system down now
" fi

Actually some statements as the first -le "80" are just for test/debug purpose. The problem with this script is the absolute_not_respect of conditionals statements with a pop-up every 5 minutes reporting the last condition "Battery critical warning...Shutting system down now".

I used crontab -e to define the following:

*/5 * * * * env DISPLAY=:0 /home/max/.bin/battery-check.sh

The contents of the script are:

#!/bin/bash                                                          

# Battery level warning script

battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`

if [[ "$battery_level" -le "80" && "$battery_level" -gt "10" ]]
    then
    notify-send "Battery low warning"  "
Battery level is ${battery_level}%"
elif [[ "$battery_level" -le "10" && "$battery_level" -gt "5" ]]
    then
    notify-send "Battery very low warning"  "
Battery level is ${battery_level}%
Use ac power now,
 or shutdown is imminent - close applications"
else [[ "$battery_level" -le "5" ]]
    # our custom actions for critical battery level
    notify-send "Battery critical warning"  "
Battery level is ${battery_level}%
Shutting system down now"
fi

Some statements, such as the first -le "80" are just for test/debug purposes. The problem with this script is that it results in a pop-up every 5 minutes reporting the last condition: "Battery critical warning...Shutting system down now".

1
source | link