Skip to content

Instantly share code, notes, and snippets.

@ahonor
Created June 3, 2011 16:01
Show Gist options
  • Save ahonor/1006584 to your computer and use it in GitHub Desktop.
Save ahonor/1006584 to your computer and use it in GitHub Desktop.
job run example via curl
#!/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
@ozbillwang
Copy link

can you show me how to transfer and use params="-method kill" to your job?

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