Skip to content

Org mode tangle not generating correct shell #66

@jamiguet

Description

@jamiguet

The following code inside a org mode buffer does what it should.
Make the request and then run the outpu json through jq and outpu in the buffer correctly formated json.

#+name: index_sizes
#+begin_src es :url localhost:9200 :var index_name="my-index-*" :jq "[.indices | to_entries[] | {\"index\": .key, \"bytes\": .value.primaries.store.size_in_bytes, \"count\": .value.primaries.docs.count, \"deleted_count\": .value.primaries.docs.deleted } ]| sort_by(.index)[]" :tangle ~/tooling/index_status.sh :shebang #!/bin/bash
GET /${index_name}/_stats
{}
#+end_src

When tangled this is the output:

#!/bin/bash
curl -XPOST localhost:9200 -d "GET /my-index-*/_stats
{}"

Which when executed does not work.

The situation can be improved if the block is modified in the following way

#+caption: Per index statistics
#+name: index_sizes
#+begin_src es :method GET :url localhost:9200/${index_name}/_stats :var index_name="my-index-*" :jq "[.indices | to_entries[] | {\"index\": .key, \"bytes\": .value.primaries.store.size_in_bytes, \"count\": .value.primaries.docs.count, \"deleted_count\": .value.primaries.docs.deleted } ]| sort_by(.index)[]" :tangle ~/tooling/index_status.sh :shebang #!/bin/bash
{}
#+end_src

But then variables are not replaced nor declared in the script.

#!/bin/bash
curl -XGET localhost:9200/${index_name}/_stats -d "{}"

Lastly the :jq command is also ignored.

Ideally the tangling of both blocks should be:

#!/bin/bash
index_name="my-index-*"
jq_cmd='[.indices | to_entries[] | {"index": .key, "bytes": .value.primaries.store.size_in_bytes, "count": .value.primaries.docs.count, "deleted_count": .value.primaries.docs.deleted } ]| sort_by(.index)[]'
echo ${jq_cmd}
curl -XGET localhost:9200/${index_name}/_stats -H Content-Type\:\ application/json -d "{}" | jq -c "${jq_cmd}"

Or follow some sort of pattern along those lines.

This would enable for the org mode document to be a prototyping environment where code and the reason why its used can live together (published as documentation) and tangled to produce running scripts.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions