added log file

This commit is contained in:
2022-01-27 19:57:26 -05:00
parent fd6877e4e8
commit a13f74c1be

View File

@@ -4,22 +4,29 @@ URL=${1}
PHONE_NUMBER=${2}
NAME=${3}
echo "URL: ${1}"
echo "Phone Number: ${2}"
echo "Name: ${3}"
LOG_FILE="/tmp/${0} ${NAME}.log"
echo "" >> ${LOG_FILE}
echo "URL: ${1}" | tee -a ${LOG_FILE}
echo "Phone Number: ${2}" | tee -a ${LOG_FILE}
echo "Name: ${3}" | tee -a ${LOG_FILE}
SOURCE_FILE="/tmp/source-${NAME}.html"
echo "${SOURCE_FILE}" >> ${LOG_FILE}
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}"
echo "Inventory Quantity: ${INVENTORY_QUANTITY}" | tee -a ${LOG_FILE}
echo "${SOURCE_FILE}" >> ${LOG_FILE}
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"
echo "Email sent" | tee -a ${LOG_FILE}
else
echo "Not sending email"
echo "Not sending email" | tee -a ${LOG_FILE}
fi