Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I want to automate the process of uploading a file to Rackspace. Here's what I need to do:

First, I type:

 curl -D - \
        -H "X-Auth-Key: 123456789abcdefghijk" \
        -H "X-Auth-User: MyUsername" \

This gives me back a response such as:

HTTP/1.1 204 No Content
Server: Apache/2.2.3 (Red Hat)
vary: X-Auth-Token,X-Auth-Key,X-Storage-User,X-Storage-Pass
Cache-Control: s-maxage=46818
Content-Type: text/xml
Date: Tue, 07 Feb 2012 05:07:09 GMT
X-Storage-Token: blahblah
Connection: Keep-Alive

Next, I need to upload a file:

curl -X PUT -T foo.txt -D - \
     -H "ETag: 7849eb8d56581fa7c4896bb0db64892c" \
     -H "Content-Type: text/plain" \
     -H "X-Auth-Token: SOME_AUTH_TOKEN_I_NEED" \
     -H "X-Object-Meta-Screenie: Test" \

So basically, I need to parse the auth token (X-Auth-Token) as well as the storage URL (X-Storage-Url) and build the next command dynamically.

Is there a way to do that with a shell script, perhaps using regular expressions or something? Any pointers would be much appreciated!

share|improve this question
up vote 3 down vote accepted

There's surely a more elegant solution than this, but off the top of my head, a quick and dirty bash way of doing it would be something like:


xauthtoken=`curl -D - \
        -H "X-Auth-Key: 123456789abcdefghijk" \
        -H "X-Auth-User: MyUsername" \ | grep X\-Auth\-Token | awk '{print $2}'`

xstorageurl=`curl -D - \
        -H "X-Auth-Key: 123456789abcdefghijk" \
        -H "X-Auth-User: MyUsername" \ | grep X\-Storage\-Url | awk '{print $2}'`

curl -X PUT -T foo.txt -D - \
     -H "ETag: 7849eb8d56581fa7c4896bb0db64892c" \
     -H "Content-Type: text/plain" \
     -H "X-Auth-Token: ${xauthtoken}" \
     -H "X-Object-Meta-Screenie: Test" \
share|improve this answer
Thanks! I ended up just writing this as a Python script instead and it works much better. I'll save this for future reference though! – Mike Christensen Feb 7 '12 at 7:25
please post your python solution as well! – ThorstenS Feb 7 '12 at 8:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.