Announcement

Collapse
No announcement yet.

Bash parse mode from status

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • mherger
    replied
    Another option I'd recommend is jq (https://stedolan.github.io/jq/), a tool which allows you to query JSON results on the command line. It's available on many systems as a package, afaik:

    Code:
    curl -sX POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "00:04:20:...", ["status","-",1] ]}' http://musicpi:9000/jsonrpc.js | jq ".result.mode"
    "stop"
    This would extract the "mode" element of the "result" within the response.

    Leave a comment:


  • RobbH
    replied
    Try this:

    Code:
    curl -s -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "aa:aa:bb:bb:cc:cc", ["'status'","-",1] ]}' http://localhost:9000/jsonrpc.js | awk -F\"mode\":\" '{print $2}' | awk -F\",\" '{print $1}'
    Awk is one tool that can be used to parse formatted text. It may or may not be the best one for this purpose, but it's the one I'm most familiar with.

    Leave a comment:


  • karadayi
    started a topic Bash parse mode from status

    Bash parse mode from status

    Hey,

    I want to parse in bash with curl the status if an audio is playing or stopped to play another audio afterwards.
    Read already "mode":"play" and "mode":"stop" with
    Code:
    curl -i -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "aa:aa:bb:bb:cc:cc", ["'status'","-",1] ]}' http://localhost:9000/jsonrpc.js
    but cant parse the mode tag to read the state and run another code.

    Adding jq to the end of URL does not help me out
    Code:
    curl -i -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "bb:bb:6c:cf:fc:b2", ["'status'","-",1,"tags"] ]}' http://localhost:9000/jsonrpc.js | jq '.'

    Would be happy for advice and help.
    Last edited by karadayi; 2022-09-11, 19:55.
Working...
X