Skip to content

Shell Access Script

frygge edited this page Jan 2, 2012 · 2 revisions

Since the command to PUT some keys is very long, the following simple shell script shall make debugging VolD with curl more easy. Indeed, it is nothing more than a wrapper to curl.

#!/bin/bash

METHOD="GET"
PARAMS=""
URL=""
CURL=$(which curl)

while [[ "$@" ]]; do
        if [[ "$1" == "-X" ]]; then
                shift
                METHOD="$1"
        elif [[ "${1:0:1}" == "-" ]]; then
                PARAMS="${PARAMS} \"$1\" \"$2\""
                shift
        else
                URL="$1"
        fi

        shift
done

echo "Method: ${METHOD}"
echo "Parameters: ${PARAMS}"
echo "URL: ${URL}"

if [[ "${METHOD}" == "PUT" ]]; then
        ${CURL} -X "${METHOD}" ${PARAMS} "${URL}" -H "Content-Type: application/xml" -d '<org.springframework.util.LinkedMultiValueMap><targetMap class="linked-hash-map"/></org.springframework.util.LinkedMultiValueMap>'
else
        ${CURL} -X "${METHOD}" ${PARAMS} "${URL}"
fi

The script can be called like curl would be called. It is sufficient to use -X METHOD to give the method (if not supplied, the default is GET) and the URL.

The following calls create a key, refresh it, get it and then delete it.

./call.sh -X PUT    "http://localhost:8080/s?k=X
./call.sh -X POST   "http://localhost:8080/s?k=X
./call.sh -X GET    "http://localhost:8080/s?k=X
./call.sh -X DELETE "http://localhost:8080/s?k=X

Clone this wiki locally