Skip to content

Instantly share code, notes, and snippets.

@jagland
Created July 14, 2020 09:15
Show Gist options
  • Save jagland/287803cf6bab3846e7f307a5179e5fc8 to your computer and use it in GitHub Desktop.
Save jagland/287803cf6bab3846e7f307a5179e5fc8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# check epson printer ink levels on an XP-235.
typeset -l PRINTERNAME
PRTINFO=`mktemp`
wget -q -O $PRTINFO http://IP/PRESENTATION/HTML/TOP/PRTINFO.HTML
VALUES=`cat $PRTINFO | grep Ink | awk -F\' '{ print $6 }' | xargs | sed -e 's/ /, /g'`
PRINTERNAME=`cat $PRTINFO | grep "Printer Name" | awk -F\> '{ print $7}' | sed -e 's$</td$
SLACKWEBHOOK="https://hooks.slack.com/services/blah"
echo $PRINTERNAME
COLOURS=(Black Yellow Magenta Cyan)
i=0
low=0
for j in $VALUES;
do
k=${COLOURS[$i]};
TEXT="$TEXT $k: $j"
VALUE=`echo $j | tr -cd [:digit:]`
if [ "$VALUE" -eq "1" ]; then
curl -X POST --data-urlencode "payload={\"channel\": \"#general\", \"username\": \"$PRINTERNAME\", \"text\": \"Printer Ink Empty - $k\", \"icon_emoji\": \":printer:\" }" $SLACKWEBHOOK
elif [ "$VALUE" -le "15" ]; then
curl -X POST --data-urlencode "payload={\"channel\": \"#general\", \"username\": \"$PRINTERNAME\", \"text\": \"Printer Ink Low - $k\", \"icon_emoji\": \":printer:\" }" $SLACKWEBHOOK
fi
i=$((i+1))
done
rm $PRTINFO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment