novacisko

jsonrpc-netcat

Mar 19th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # NOTE: Depends on "jq" - http://stedolan.github.io/jq/
  4. #
  5. # example of call:  getblockhash [12345]
  6. #                   getrawtransaction ["6ab513d9bc689089de3b5e2130a2dad70af76f2b108dc30e81a836e9abb31a4e"]
  7. #
  8.  
  9. if [ '$1' == '' ]; then
  10.     echo "Usage: $0 <url> [username] [password]"
  11.     exit 1
  12. fi
  13.  
  14. server="$1"
  15. prompt="$server>"
  16.  
  17. username="$2"
  18. password="$3"
  19.  
  20. history -r ~/.jsonrpc-netcat.hist
  21.  
  22. while read -p "$prompt" -e  line; do
  23.  
  24.     if [ "$line" != "" ]; then
  25.     history -s "$line"
  26.  
  27.     cmd="$( cut -d '[' -f 1 <<< "$line" )"
  28.     args="$( cut -d '[' -f 2- <<< "$line" )"
  29.     args="[$args"
  30.     cmd="$( cut -d ' ' -f 1 <<< "$cmd" )"
  31.  
  32.  
  33.         request="{\"method\":\"$cmd\", \"params\":$args, \"id\":\"foo\"}"
  34.    
  35.         result=$(wget --http-user=$username -nv --http-password=$password --progress=dot --header="Content-Type: application/json" --header="Accept: application/json" "--post-data=$request" --header="Connection: close" -O - $server)
  36.         echo -n "ERROR: "
  37.         echo $result | jq .error
  38.         echo -n "RESULT: "
  39.         echo $result | jq .result
  40.  
  41.     fi;
  42.  
  43.  
  44. done
  45. echo ""
  46. history -w ~/.jsonrpc-netcat.hist
Advertisement
Add Comment
Please, Sign In to add comment