Created
June 2, 2017 07:10
-
-
Save sourceperl/534d3d43304a427ba737eda3026dc472 to your computer and use it in GitHub Desktop.
Command line tool to update thingspeak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Update thingspeak from command line | |
# Usage : thingspeak WRITE_API_KEY DATA | |
# Example : thingspeak XXXXXXXXXXXX field1=11&field2=12 | |
# consts | |
URL="https://api.thingspeak.com/update" | |
# vars | |
NAME=$(basename $0) | |
# parse optionals args | |
while getopts 'h' OPTION | |
do | |
case $OPTION in | |
h) | |
printf "Usage : %s [-h] WRITE_API_KEY DATA\n" $NAME | |
printf "Example: %s XXXXXXXXXXXXX field1=11&field2=2\n" $NAME | |
printf "\n" | |
printf " -h print this help message\n" | |
exit 0 | |
;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
# parse fixed args | |
KEY=$1 | |
DATA=$2 | |
# some checks | |
[ $# -ne 2 ] && { printf "ERROR: $NAME needs 2 args\n" 1>&2; exit 1; } | |
# do the job | |
curl "$URL?api_key=$KEY&$DATA" &>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment