Created
May 17, 2017 01:10
-
-
Save clofresh/96e4e58f726c1314bdd320ed47dc0f50 to your computer and use it in GitHub Desktop.
atomic counter in consul
This file contains 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 | |
KEY=$1 | |
VAL=$2 | |
MAX=${3-10} | |
if [ -z $KEY ]; then | |
echo "Must specify a key" >&2 | |
exit 1 | |
fi | |
if [ -z $VAL ]; then | |
echo "Must specify a value" >&2 | |
exit 1 | |
fi | |
for i in $(seq $MAX); do | |
OUTPUT=$(curl -s --fail -X PUT "http://localhost:8500/v1/kv/$KEY/$i?cas=0" -d "$VAL") | |
if [ $? -eq 0 ] && [[ $OUTPUT == true ]]; then | |
echo $i | |
exit 0 | |
fi | |
done | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment