Skip to content

Instantly share code, notes, and snippets.

@sameer
Created November 28, 2016 17:16
Show Gist options
  • Save sameer/a63f7f52afd4657ad2931b064c03bf7e to your computer and use it in GitHub Desktop.
Save sameer/a63f7f52afd4657ad2931b064c03bf7e to your computer and use it in GitHub Desktop.
Script that runs only if battery > 50% (tested on Ubuntu 16.04 4.4.0-47-generic)
#!/bin/bash
command() {
# enter command here
}
POWER=`upower -i $(upower -e | grep BAT) | grep --color=never -E percentage|xargs|cut -d' ' -f2|sed s/%//`
if [ "$POWER" -gt "50" ]
then
command
else
echo "Refusing to run command, battery is low."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment