Last active
March 5, 2023 06:16
-
-
Save bjoern-r/c3afda16d45edad5f4a5 to your computer and use it in GitHub Desktop.
simple shell xmlrpc client that uses bash & curl
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 | |
# author [email protected] | |
TEMP=`getopt -o vt: --long target -n 'example.bash' -- "$@"` | |
if [ $? != 0 ] ; then echo "getopt fail, terminating..." >&2 ; exit 1 ; fi | |
# Note the quotes around `$TEMP': they are essential! | |
eval set -- "$TEMP" | |
Usage() { | |
echo "usage: $0 -t <rpcServUrl> <method> [arg1 arg2 ...]" | |
exit 1 | |
} | |
simpleArg() { | |
local arg="$1" | |
local type=${arg%%:*} val=${arg#*:} | |
echo -e "${indent}<param><value><$type>$val</$type></value></param>" | |
} | |
structArg() { | |
local arg="$1" | |
: parse wait complete ... | |
} | |
while true ; do | |
case "$1" in | |
-t|--target) servUrl=$2; shift 2;; | |
-v) verbose=--verbose; shift;; | |
--) shift; break;; | |
*) echo "Internal error!"; exit 1;; | |
esac | |
done | |
[ -z "$servUrl" ] && Usage | |
[ $# -lt 1 ] && Usage | |
#<method> <arg1> <arg2> ... <argx> | |
generateRequestXml() { | |
method=$1; shift | |
echo '<?xml version="1.0"?>' | |
echo "<methodCall>" | |
echo " <methodName>$method</methodName>" | |
echo " <params>" | |
indent=" " | |
for arg; do | |
indent="${indent} " | |
case $arg in | |
struct:*) structArg "$arg";; | |
*) simpleArg "$arg";; | |
esac | |
done | |
echo " </params>" | |
echo "</methodCall>" | |
} | |
rpcxml=rpc$$.xml | |
generateRequestXml "$@" > $rpcxml | |
[ "$verbose" = "--verbose" ] && cat "$rpcxml" | |
curl -k $verbose --data "@$rpcxml" "$servUrl" 2>/dev/null | xmllint --format - | |
\rm -f $rpcxml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks a lot. This is my example.
I run server.py on linux, and use this shell script like this.
./xmlrpc_client.sh -t "xx.xx.xx.xx:8085" -- add int:1 int:2
the server.py is like this: