How to retrieve the log of a Rundeck job when I run it via curl?

985 views
Skip to first unread message

Timeu Oliveira

unread,
Aug 22, 2022, 6:12:41 PM8/22/22
to rundeck-discuss

A job in Rundeck is being executed through a shell script using curl but the response I get is just the output of the HTTP Request made by curl.

How do I get the Rundeck job log output to show after running the script with curl?

rac...@rundeck.com

unread,
Aug 22, 2022, 6:29:22 PM8/22/22
to rundeck-discuss

Hi Tim,

It’s possible in two steps: the first one running the job, taking the execution ID via JQ, and then, printing the output of that execution id through this endpoint.

I tested with this script example:

# store the exec id on a variable
my_exec=$(curl -s -X POST 'http://localhost:4440/api/41/job/1a5b1774-2c03-4313-b6fb-f66d0a96f7fb/run'  --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: h8HWwRSojZ0Ip2it2jLJDZ80FmktDUNF' | jq -r '.id')

# few seconds until the end of the execution
sleep 5

# and then print the output (entries section)
curl -s -X GET "http://localhost:4440/api/41/execution/$my_exec/output" --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: h8HWwRSojZ0Ip2it2jLJDZ80FmktDUNF'

Hope it helps!

Timeu Oliveira

unread,
Aug 23, 2022, 8:08:17 AM8/23/22
to rundeck-discuss
Thanks! It helped a lot.

Now I just have one more issue. The host that's making the curl request is "a little bit" old and doesn't have JQ, not even in the repositories.
I just need to trate the curl output manualy.

Message has been deleted

rac...@rundeck.com

unread,
Aug 23, 2022, 9:45:38 AM8/23/22
to rundeck-discuss

Hi Tim,

Using grep + awk it’s possible:

my_exec=$( curl -s -X POST 'http://localhost:4440/api/41/job/d56c8c43-de29-4b17-8a0c-3cab8728df55/run'  --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: k5k80EqvrPgieRQXz2Pa2JHcT5SLZ2yh' | grep -o -E "\"id\":[0-9]+" | awk -F\: '{print $2}' )

sleep 5

curl -s -X GET "http://localhost:4440/api/41/execution/$my_exec/output" --header 'Accept: application/json' --header 'X-Rundeck-Auth-Token: k5k80EqvrPgieRQXz2Pa2JHcT5SLZ2yh'

Greetings!

PD: I deleted the last post due to “formatting” issues.

Timeu Oliveira

unread,
Aug 23, 2022, 10:25:25 AM8/23/22
to rundeck-discuss
This was exactly what I was thinking...

Thanks again! Have a great week!

Reply all
Reply to author
Forward
0 new messages