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" \
https://auth.api.rackspacecloud.com/v1.0
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
X-Storage-Url: https://storage101.ord1.clouddrive.com/v1/BlahBlah
Cache-Control: s-maxage=46818
Content-Type: text/xml
Date: Tue, 07 Feb 2012 05:07:09 GMT
X-Auth-Token: SOME_AUTH_TOKEN_I_NEED
X-Storage-Token: blahblah
X-Server-Management-Url: https://servers.api.rackspacecloud.com/v1.0/123456
Connection: Keep-Alive
X-CDN-Management-Url: https://cdn2.clouddrive.com/v1/BlahBlah
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" \
https://storage101.ord1.clouddrive.com/v1/BlahBlah/MyBackup/foo.txt
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!