Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing JSON output in curl bash script
    text
    copied!<p>I want to upload a file automatically to rackspace files which requires an auth-token that is updated daily, so I want to create a script which gets the auth token and then uses that in the script to upload the file. </p> <p>This is the command to get the auth token which outputs the key perfectly:</p> <pre><code>curl -s -X POST https://auth.api.rackspacecloud.com/v2.0/tokens\ -d '{ "auth":{ "RAX-KSKEY:apiKeyCredentials":{ "username":"USER", "apiKey":"KEY" } } }'\ -H "Content-type: application/json" | python -mjson.tool |\ python -c 'import sys, json;\ print json.load(sys.stdin)[sys.argv[1]][sys.argv[2]][sys.argv[3]]'\ access token id </code></pre> <p>This is the command to upload the file:</p> <pre><code>curl -X PUT -T file.xml -D - \ -H "Content-Type: text/xml" \ -H "X-Auth-Token: TOKENGOESHERE" \ URL </code></pre> <p>I need to get the token from the first command into the TOKENGOESHERE place in the second command.</p> <p>What I have tried so far is: </p> <pre><code>token = curl -s -X POST https://auth.api.rackspacecloud.com/v2.0/tokens -d '{ "auth":{ "RAX-KSKEY:apiKeyCredentials":{ "username":"USER", "apiKey":"KEY" } } }' -H "Content-type: application/json" | python -mjson.tool | python -c 'import sys, json; print json.load(sys.stdin)[sys.argv[1]][sys.argv[2]][sys.argv[3]]' access token id curl -X PUT -T file.xml -D - \ -H "Content-Type: text/xml" \ -H "X-Auth-Token: $token" \ URL </code></pre> <p>but it didn't work and I am guessing it has something to do with the quotes but I don't know enough about bash to know what the problem is.</p> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload