I have a command like this:
if [ $battery_level -le 6 -a $STATUS = $NOT_CHARGING ] #Battery Low 1
then
/usr/bin/notify-send -i "$ICONL" "Battery critically low!" "Battery level is ${battery_level}%!"
paplay /usr/share/sounds/freedesktop/stereo/dialog-information.oga
It gives a message and a sound at a certain battery level. But it repeats too often.
I can set it to sleep and run again by separating the same command with a line like sleep 120s
, but I do not know exactly how many times should it be run.
I need it to run at an interval of two minutes, indefinitely (as at some point system sleep or hibernation is triggered by a completely different script).
Looking here: How to Run or Repeat a Linux Command Every X Seconds Forever, I see that an option is sleep
and the other is watch
.
watch
seems to work but it only works with the form
watch -n 120 <my_line>
, and that changes a bit the output (battery level is not shown) anymore.
while
in place ofif
and place the whole code you show in file+make it executable. And then, justwatch -n 120 your_battery_level_indicator.sh