Skip to content

Instantly share code, notes, and snippets.

@raghur
Created November 12, 2018 17:47
Show Gist options
  • Save raghur/8493cbf54d13ff83b330878a2dbf1a71 to your computer and use it in GitHub Desktop.
Save raghur/8493cbf54d13ff83b330878a2dbf1a71 to your computer and use it in GitHub Desktop.
Router to check HP ink levels and notify
#! /opt/bin/bash
# replace these
user="user token"
token="app token"
mypidfile=/tmp/levels.sh.pid
if [ -e $mypidfile ]; then
exit 0
fi
trap "rm -f $mypidfile" EXIT
echo $$ > "$mypidfile"
if [ -e /dev/lp0 ]; then
sleep 15
# check if /dev/lp0 is still around
# hotplug script gets called both when device is plugged or unplugged
levels=`hp-info -i|grep 'agent[0-9]-level '|sed -e 's/agent1-/Color /' | sed -e 's/agent2-/Black /' `
if [ ! -z "$levels" ]; then
logger -t printer $levels
curl -d "user=$user" -d "token=$token" -d "message=$levels" https://api.pushover.net/1/messages.json
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment