Files
homelab-scripts/ubiquiti_stock.sh
2022-01-27 18:48:52 -05:00

18 lines
490 B
Bash

#!/bin/bash
URL=${1}
PHONE_NUMBER=${2}
SOURCE_FILE='/tmp/source.html'
wget -qO ${SOURCE_FILE} ${URL}
INVENTORY_QUANTITY=$(grep -o -m 1 '"inventory_quantity":[0-9]\+,' ${SOURCE_FILE} | grep -o '[0-9]\+')
if [[ "${INVENTORY_QUANTITY}" -gt "0" ]]; then
MESSAGE="There are currently ${INVENTORY_QUANTITY} in stock. ${URL}"
echo "${MESSAGE}" | \
mailx -r "stockalerts@johnhgaunt.com" \
--set smtp="smtp.home.johnhgaunt.com:25" \
${PHONE_NUMBER}@vtext.com
fi