Created
November 12, 2018 17:47
-
-
Save raghur/8493cbf54d13ff83b330878a2dbf1a71 to your computer and use it in GitHub Desktop.
Router to check HP ink levels and notify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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