-
-
Save ozbillwang/1533bba1dcd66747d3f9 to your computer and use it in GitHub Desktop.
job run example via curl
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 | |
#!/bin/bash | |
#Utility to log into the RunDeck server and store cookie file for later use | |
errorMsg() { | |
echo "$*" 1>&2 | |
} | |
url_encode() { | |
[ $# -lt 1 ] && { return; } | |
printf "%s" $1 | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' | |
} | |
DIR=/tmp | |
url=${1:-http://localhost:4440} | |
apiurl="${url}/api" | |
loginurl="${url}/j_security_check" | |
VERSHEADER="X-RUNDECK-API-VERSION: 1.2" | |
# curl opts to use a cookie jar, and follow redirects, showing only errors | |
CURLOPTS="-k -s -S -L -c $DIR/cookies -b $DIR/cookies" | |
CURL="curl $CURLOPTS" | |
# credentials | |
RDUSER=admin | |
RDPASS=admin | |
RDPASS=$(url_encode ${RDPASS}) | |
# login | |
$CURL --header "$VERSHEADER" -d j_username="$RDUSER" -w 'login %{time_total}\n' --data-binary j_password="${RDPASS}" -o $DIR/curl.out $loginurl | |
if [ 0 != $? ] ; then | |
errorMsg "failed login request to ${loginurl}" | |
exit 2 | |
fi | |
grep 'j_security_check' -q $DIR/curl.out | |
if [ 0 == $? ] ; then | |
errorMsg "login was not successful" | |
exit 2 | |
fi | |
# run a job | |
params="-method kill" | |
$CURL -w "run 5 %{time_total}\n" -o $DIR/curl.run.out --data-urlencode "argString=$params" ${url}/api/1/job/15/run | |
echo result: | |
cat $DIR/curl.run.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment