Skip to content

Instantly share code, notes, and snippets.

@stephenturner
Last active November 25, 2017 15:43
Show Gist options
  • Save stephenturner/bbd16f517a1e14b98450 to your computer and use it in GitHub Desktop.
Save stephenturner/bbd16f517a1e14b98450 to your computer and use it in GitHub Desktop.
Uses the http://textbelt.com/ API to send a text message.
#!/bin/bash
# Uses the http://textbelt.com/ API to send a text message.
# The PHONE environment variable must be set, e.g., in your .bashrc., e.g.
# export PHONE=1234567890
# Usage: txt "<a text message to send>"
# Example 1
# When long_running_command is done successfully, this command
# will send a text to the indicated number saying:
# "done with long running command (from myusername on myhostname)"
# long_running_command && txt 'done with long running command'
# Example 2
# Tells you whether command succeeded or failed
# command && txt success || txt fail
if [ -z "$PHONE" ]; then
echo 'Environment variable $PHONE is not set. Set this in .bashrc and try again.'
exit 1
else
curl --silent -X POST http://textbelt.com/text -d number=$PHONE -d "message=$1 (from $(whoami) on $(hostname))" > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment