Skip to content

Instantly share code, notes, and snippets.

@justlooks
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justlooks/709a312fdf0ed38935c8 to your computer and use it in GitHub Desktop.
Save justlooks/709a312fdf0ed38935c8 to your computer and use it in GitHub Desktop.
# curl -k http://192.168.10.231:8888 -H "X-Auth-Token:7715cc6c49dc652820c25e4c09684c49bfd9ccf9" -d client='local_async' -d tgt='saltslave2' -d fun='state.sls' -d arg='tomcat.newinstance'
{"return": [{"jid": "20140327162916805438", "minions": ["saltslave2"]}]}
# curl -k http://192.168.10.231:8888 -H "X-Auth-Token:7715cc6c49dc652820c25e4c09684c49bfd9ccf9" -d client='local' -d tgt='saltslave2' -d fun='state.sls' -d arg='tomcat.newinstance'
{"return": [{}]}
@whiteinge
Copy link

echo '[{"client": "local", "tgt": "saltslave2", "fun": "state.sls", "arg": ["tomcat.newinstance"], "timeout": 300}]' | curl -k http://192.168.10.231:8888 -H "X-Auth-Token:7715cc6c49dc652820c25e4c09684c49bfd9ccf9" -H "Content-type: application/json" -d@-

@whiteinge
Copy link

Here's a three-liner that will wait indefinitely for a job to complete. This will not have timeout issues.

# Log in:
% curl -c /tmp/cookies.txt -sSi http://localhost:8000/login -d username='saltdev' -d password='saltdev' -d eauth='auto' | head -1 | grep -q '200 OK'

# Get the JID:
% jid=$(curl -b /tmp/cookies.txt -sS http://localhost:8000 -d client='local_async' -d tgt=jerry -d fun='test.sleep' -d arg='8' | sed -r -n -e 's/.*jid": "([0-9]+).*/\1/p')

# Wait for the JID:
% curl -b /tmp/cookies.txt -NsS http://localhost:8000/events 2>/dev/null | while read -r line; do { printf '%s\n' "$line" | grep -q "^data:.*$jid" && printf "%s\n" "$line" && break; }; done

(This example will require modification in order to listen for more than one JID or more than one minion.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment