Skip to content

Instantly share code, notes, and snippets.

@EkoAdiWijayanto
Created January 14, 2016 22:13
Show Gist options
  • Save EkoAdiWijayanto/d93b90c2a7254bec6a27 to your computer and use it in GitHub Desktop.
Save EkoAdiWijayanto/d93b90c2a7254bec6a27 to your computer and use it in GitHub Desktop.
#!/bin/bash
DIR="/sys/class/power_supply/BAT0"
for PREFIX in "charge" "energy"
do
if [ -f "$DIR/${PREFIX}_now" ] && [ -f "$DIR/${PREFIX}_full" ]
then
echo "$DIR/${PREFIX}_now"
echo "$DIR/${PREFIX}_full_design"
for i in 0 2 3 4 5 6 7 8 9
do
for j in 0 1 2 3
do
REMAIN=$(cat "$DIR/${PREFIX}_now")
FULL=$(cat "$DIR/${PREFIX}_full_design")
PRCT=$((100 * $REMAIN / $FULL))
STATUS=$(cat "$DIR/status")
echo $REMAIN
echo $FULL
echo $STATUS
echo $PRCT
if [[ $PRCT -lt 15 && "$STATUS" == "Discharging" ]] || [[ $PRCT -gt 80 && "$STATUS" != "Discharging" ]]
then
/usr/bin/mplayer --quiet -ao pulse -loop 2 /home/work/Downloads/alert.mp3
sleep 5
fi
done
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment