#! /bin/bash
# read battery percentage value
OUT='upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep percentage'
# select only the int value
IFS=':' read -ra P <<< "$OUT"
PERCENTAGE="%"
BATTERY_VALUE=${P[1]%$PERCENTAGE}
# send a notification if battery level is under 15% and not on AC power
if ! on_ac_power; then
if (($BATTERY_VALUE < "15")); then
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
notify-send -u critical -i "battery-caution" "Battery low! You should plug in your laptop!"
/usr/bin/aplay /usr/share/sounds/desktop-logout.oga
fi
fi
# send a notification if battery level is equal to or over 90% and is on AC power
if on_ac_power; then
if (($BATTERY_VALUE >= "90")); then
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
notify-send -u critical -i "battery-full-charging" "Battery charged! You should unplug your laptop!"
/usr/bin/aplay /usr/share/sounds/desktop-logout.oga
fi
fi
Som e script funcionando corretamente se eu executar o script manualmente. Recebo uma notificação do envio de notificação, mas não reproduz som do crontab. Cron log está dizendo:
Connection failure: Connection refused
pa_context_connect() failed: Connection refused.
Eu tentei o comando paplay e apontei para o caminho absoluto da paplay em /usr/bin/paplay
sem sucesso.