Created
October 22, 2018 09:17
-
-
Save pkazi/d2a492b0739779ba9584bed0a2dda4e5 to your computer and use it in GitHub Desktop.
DCOS Get tasks by node IP using Rest api and cli
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 | |
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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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