Skip to content

Instantly share code, notes, and snippets.

@brwyatt
Last active January 28, 2023 01:05
Show Gist options
  • Save brwyatt/2a4ad6b0403ec1345e5af9ec8f75ecf7 to your computer and use it in GitHub Desktop.
Save brwyatt/2a4ad6b0403ec1345e5af9ec8f75ecf7 to your computer and use it in GitHub Desktop.
Ubiquiti Store stock checker
#!/bin/bash
models=(
"switch-enterprise-8-poe"
"usw-enterprise-24-poe"
"usw-enterprise-48-poe"
"usp-rps"
)
do_check () {
for model in "${models[@]}"; do
url="https://store.ui.com/products/${model}"
status=$( \
curl -s -q -L "${url}" \
| grep -E 'span id="title(InStock|SoldOut)Badge"' \
| sed -r 's/^\s*<.*>(.*)<\/span>/\1/' \
)
if [ $? -ne 0 ]; then
status="\e[43mERROR"
else
if [[ "${status}" == "In Stock" ]]; then
status="\a\e[42m${status}"
elif [[ "${status}" == "Sold Out" ]]; then
status="\e[41m${status}"
fi
fi
printf "| %-25s | %-8b\e[0m | %-90s |\n" "${model}" "${status}" "${url}"
done
}
if [[ "$1" == "-r" ]]; then
while true; do
echo "============================="
echo "= $(date -Iseconds) ="
echo "============================="
do_check
echo "Sleeping..."
sleep 30
done
else
do_check
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment