Skip to content

Instantly share code, notes, and snippets.

@elico
Created March 27, 2022 04:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elico/2755efac14ed47a0dee59e186e176ed8 to your computer and use it in GitHub Desktop.
Save elico/2755efac14ed47a0dee59e186e176ed8 to your computer and use it in GitHub Desktop.
Sending a SMS from a mikrotik LTE device reset API
#!/usr/bin/env bash
ALLOWED_NUMBERS_FILE="destinations.txt"
MOBILE_NUMBER="$1"
DRY_RUN="0"
if [ -f "dry-run" ];then
DRY_RUN="1"
echo "### RUNNING IN DRY RUN MODE ###"
echo
echo
fi
if [ -z "${MOBILE_NUMBER}" ];then
echo "Missing mobile number"
exit 1
fi
grep "${MOBILE_NUMBER}" "${ALLOWED_NUMBERS_FILE}" >/dev/null
if [ "$?" -gt "0" ];then
echo "This mobile number: \"${MOBILE_NUMBER}\" is not allowed"
exit 3
fi
MSG="$2"
if [ -z "${MSG}" ];then
echo "Missing message text to send in the sms"
exit 2
fi
USER="admin"
PASSWORD="1234"
LTE_ROUTER_ADDRESS="192.168.88.1"
URL="https://${LTE_ROUTER_ADDRESS}/rest/tool/sms/send"
echo "Sending sms to: \"${MOBILE_NUMBER}\" via URL: \"${URL}\""
echo "Message: \"${MSG}\""
JSON_DATA="{\"port\" : \"lte1\", \"message\" : \"${MSG}\", \"phone-number\" : \"${MOBILE_NUMBER}\"}"
if [ "${DRY_RUN}" -eq "0" ];then
curl -k -u ${USER}:${PASSWORD} ${URL} \
-H "Content-Type: application/json" \
--data "${JSON_DATA}"
else
echo
echo "DRY RUN, should send the next JSON to the LTE Router"
echo
echo "${JSON_DATA}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment