0

I am making in-roads to getting a curl script to work as intended, working around some issue that requires pagination. My point is... the curl part works, BUT I can't get the output to log to a file.

#!/usr/bin/env bash
# Author: Scouse Bob
# ----------------------------------------
log="/tmp/bob.log">>"${log}"

i=0
while [[ $i -lt 700 ]]
do curl -i -X GET "https://bob_server.atlassian.net/rest/api/3/project/search?jql=ORDER%20BY%20Created&maxResults=50&startAt=$i" --user bob@abcde.com:<token_id> --header Accept: application/json; (( i+=50 )); >>"${log}"; done

I have tested the above in various forms and if I take the log parts out, the script outputs to the screen.

Does anyone know why the loop won't output to the log I'm trying to create please?

1 Answer 1

7

You have >> "$log", but it does not receive any input as it comes after a ;.

Either put it after done:

while ... do ... done >> "$log"

or after the curl command:

curl ... >> "$log"; done

Note also, that you should quote your --header and --user string:

--header "Accept: application/json"

Also, you could more easily use a for-loop:

for i in $(seq 0 50 700); do ... done

In total:

log="/tmp/bob.log">>"${log}"

for i in $(seq 0 50 700); do
    curl -i -X GET "https://bob_server.atlassian.net/rest/api/3/project/search?jql=ORDER%20BY%20Created&maxResults=50&startAt=$i" --user "bob@abcde.com:<token_id>" --header "Accept: application/json"
done >> "${log}"

or without seq:

for (( i=0; i <= 700; i += 50)); do
   ...
done
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.