-
-
Save shagamemnon/2cedf12c77c5640a2820f78489f22576 to your computer and use it in GitHub Desktop.
Extract a JSON value from a BASH script
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 | |
function jsonval { | |
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop` | |
echo ${temp##*|} | |
} | |
json=`curl -s -X GET https://api.cloudflare.com/client/v4/zones?account.name=$ACCT_NAME&page=1&per_page=1000&order=status&direction=desc&match=all` | |
prop='profile_image_url' | |
picurl=`jsonval` | |
`curl -s -X GET $picurl -o $1.png -H "X-Auth-Email: $ACCT_EMAIL" -H "X-Auth-Key: $GLOBAL_API_KEY" -H "Content-Type: application/json"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment