25 lines
645 B
Bash
25 lines
645 B
Bash
#!/bin/bash
|
|
|
|
URL=${1}
|
|
PHONE_NUMBER=${2}
|
|
NAME=${3}
|
|
|
|
echo "URL: ${1}"
|
|
echo "Phone Number: ${2}"
|
|
echo "Name: ${3}"
|
|
|
|
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]\+')
|
|
|
|
echo "Inventory Quantity: ${INVENTORY_QUANTITY}"
|
|
|
|
if [[ "${INVENTORY_QUANTITY}" -gt "0" ]]; then
|
|
MESSAGE="There are currently ${INVENTORY_QUANTITY} ${NAME} in stock. ${URL}"
|
|
echo "${MESSAGE}" | mailx -r "stockalerts@johnhgaunt.com" --set smtp="smtp.home.johnhgaunt.com:25" ${PHONE_NUMBER}@vtext.com
|
|
echo "Email sent"
|
|
else
|
|
echo "Not sending email"
|
|
fi |