Skip to content

Instantly share code, notes, and snippets.

@pkazi
Created October 22, 2018 09:17
Show Gist options
  • Save pkazi/d2a492b0739779ba9584bed0a2dda4e5 to your computer and use it in GitHub Desktop.
Save pkazi/d2a492b0739779ba9584bed0a2dda4e5 to your computer and use it in GitHub Desktop.
DCOS Get tasks by node IP using Rest api and cli
#!/bin/bash
function tasksByNodeAPI
{
echo "DC/OS Tasks By Node"
if [ "$#" -eq 0 ]; then
echo "Need node ip as input. Exiting."
exit 1
fi
nodeIp=$1
mesosId=`dcos node | grep $nodeIp | awk '{print $3}'`
if [ -z "mesosId" ]; then
echo "No node found with ip $nodeIp. Exiting."
exit 1
fi
curl -s -H "Authorization: Bearer $(dcos config show core.dcos_acs_token)" "$(dcos config show core.dcos_url)/mesos/tasks?limit=10000" | jq --arg mesosId $mesosId '.tasks[] | select (.slave_id == $mesosId and .state == "TASK_RUNNING") | .name + "\t\t\t" + .id' -r
}
function tasksByNodeCLI
{
echo "DC/OS Tasks By Node"
if [ "$#" -eq 0 ]; then
echo "Need node ip as input. Exiting."
exit 1
fi
nodeIp=$1
dcos task | egrep "HOST|$nodeIp"
}
@nferouz89
Copy link

if u run this script im not getting any output

and if im running only the curl command with the relevant node and mesosId , im getting the below :

curl -s -H "Authorization: Bearer $(dcos config show core.dcos_acs_token)" "$(dcos config show core.dcos_url)/mesos/tasks?limit=10000" | jq --arg mesosId $mesosId '.tasks[] | select (.slave_id == $mesosId and .state == "TASK_RUNNING") | .name + "\t\t\t" + .id' -r

parse error: Invalid numeric literal at line 1, column 10

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