# Generating a CSV file from curl with Kibana, results in just 'Processing' in the output csv file

**URL:** https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374
**Category:** Kibana
**Created:** [March 25, 2021, 3:24pm UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374 "2021-03-25T15:24:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)
#### Post date: [March 25, 2021, 3:24pm UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374/1 "2021-03-25T15:24:10Z")

</div>

I am using the following shell snipped to download csvs for a a series of queries that I have collected up in Kibana:

```auto
                for filename in ${KIBANA_QUERIES}/*.rison; do
                   echo "Processing query file: $filename"
                   CSV_REPORT=$(basename $filename.csv)
                   REPORT_PATH=$(curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" -H "kbn-version: 7.11.2" -XPOST $(cat $filename) | jq -r '.path')
                   echo "Report path: $REPORT_PATH"
                   echo "Downloading report to: $CSV_REPORT"
                   curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" https://${K8S_NODE_IP}:${KIBANA_NODE_PORT}${REPORT_PATH} --output $HOME/Downloads/$CSV_REPORT
                done

```

When I run this command, the csv report that comes out just contains the work 'Processing'. Is there a way to wait until the csv report is ready? I am version 7.10 of the ELK stack.

---

<div class="post-metadata">

### Author: ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)
#### Post date: [March 25, 2021, 3:52pm UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374/2 "2021-03-25T15:52:57Z")

</div>

You can poll the status code of the report path request - once it becomes 200, the report is ready.

---

<div class="post-metadata">

### Author: ![eeijlar](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@eeijlar](https://discuss.elastic.co/u/eeijlar)
#### Post date: [March 27, 2021, 1:13pm UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374/3 "2021-03-27T13:13:48Z")

</div>

Hi Joe,

I tried what you suggested like this:

```auto
                for filename in ${KIBANA_QUERIES}/*.rison; do
                   echo "Processing query file: $filename"
                   CSV_REPORT=$(basename $filename.csv)
                   REPORT_READY=400
                   while ["${REPORT_READY}" != "200"]
                   do
                     REPORT_READY=$(curl -I -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" -H "kbn-version: 7.11.2" -XPOST $(cat $filename) | grep HTTP | awk '{print $2}')
                     if ["$REPORT_READY" == "404"]; then
                         echo "Exiting on 404"
                         break;
                     fi
                     sleep 1
                     echo "Waiting for report to be ready, status $REPORT_READY"
                   done

                   if ["$REPORT_READY" == 200]; then
                      REPORT_PATH=$(curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" -H "kbn-version: 7.11.2" -XPOST $(cat $filename) | jq -r '.path')
                      echo "Report path: $REPORT_PATH"
                      echo "Downloading report to: $CSV_REPORT"
                      curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" https://${K8S_NODE_IP}:${KIBANA_NODE_PORT}${REPORT_PATH} --output $HOME/Downloads/$CSV_REPORT
                   fi
                done

```

But I get the same result. Perhaps my polling logic is wrong?

---

<div class="post-metadata">

### Author: ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)
#### Post date: [March 30, 2021, 8:02am UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374/4 "2021-03-30T08:02:00Z")

</div>

Hey, sorry for the late answer. In your new script it seems like you aren't extracting the path.

The idea is the following:

- Kick off the report generation with the POST url copied from the UI (send as POST request)
- This returns 200 immediately, and the response contains the path
- Poll the path via GET request, until the response code turns 200
- Once the response code turns 200, the response body will be the final report

Your second script seems to poll the initial post request instead.

My shell scripting game is really low, but something like this:

```auto
                for filename in ${KIBANA_QUERIES}/*.rison; do
                   echo "Processing query file: $filename"
                   CSV_REPORT=$(basename $filename.csv)
                   REPORT_PATH=$(curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" -H "kbn-version: 7.11.2" -XPOST $(cat $filename) | jq -r '.path')
                   echo "Report path: $REPORT_PATH"
                   REPORT_READY=400
                   while ["${REPORT_READY}" != "200"]
                   do
                     REPORT_READY=$(curl -I -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" https://${K8S_NODE_IP}:${KIBANA_NODE_PORT}${REPORT_PATH} | grep HTTP | awk '{print $2}')
                     if ["$REPORT_READY" == "404"]; then
                         echo "Exiting on 404"
                         break;
                     fi
                     sleep 1
                     echo "Waiting for report to be ready, status $REPORT_READY"
                   done

                   if ["$REPORT_READY" == 200]; then
                      echo "Downloading report to: $CSV_REPORT"
                      curl -s --insecure -u "elastic:${ELASTIC_SECRET_UMS}" https://${K8S_NODE_IP}:${KIBANA_NODE_PORT}${REPORT_PATH} --output $HOME/Downloads/$CSV_REPORT
                   fi
                done

```

It's downloading the final report twice, it's probably possible to optimize that, but I don't know how (you need to get the status code and the response body in the same call)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 27, 2021, 8:02am UTC](https://discuss.elastic.co/t/generating-a-csv-file-from-curl-with-kibana-results-in-just-processing-in-the-output-csv-file/268374/5 "2021-04-27T08:02:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
