# How to use a dynamic value (from shell?) in input { } configuration?

**URL:** <https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208>\
**Category:** Logstash\
**Created:** [April 12, 2017, 5:47pm UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208 "2017-04-12T17:47:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [April 12, 2017, 5:47pm UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208/1 "2017-04-12T17:47:07Z")

</div>

I'm testing logstash for the first time, and I'm using it to get data from a database.

I've already managed to configure jdbc-input pluging, and I'm using a query that uses a date as a parameter.

```
...
parameters => { "date" => "20170417" }
statement => "SELECT id, date, doc, value FROM table WHERE date = :data"
...

```

I'd need to get this `date` parameter from the current date, and I thought I could use a bash script like `date +%Y%m%d` to get this date.

Is that possible, or is there any other solution I can use ?

It would be something like this

```
...
parameters => { "date" => $(date +%Y%m%d) }
statement => "SELECT id, date, doc, value FROM table WHERE date = :data"
...
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 13, 2017, 7:06am UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208/2 "2017-04-13T07:06:30Z")

</div>

In many cases you can use `${varname}` to reference environment variables but you can't get Logstash to run a command like in your example. Why do you need the current date? Maybe there's another way of accomplishing your end goal.

---

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [April 13, 2017, 12:32pm UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208/3 "2017-04-13T12:32:38Z")

</div>

Maybe %{varname} can help in most cases.

For the current date, in this case that I'm using jdbc, I can get it via T-SQL.

---

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [April 13, 2017, 12:41pm UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208/4 "2017-04-13T12:41:43Z")

</div>

@magnusbaeck I thought of a case where I could need to get the output of a shell command.

I've been using logstash's docker image, and recente versions of Docker has a `docker secrets` option, so I can save passwords and other sensitive information.

Tha way docker makes it available to containers is via a tmpfs filesystem at `/run/secrets` directory, and won't use environment variables anymore.

So if I need a password created via `docker secret create mypassword` I need to get its content via `cat /run/secrets/mypassword`

This should be a nice example of the need to get the output of a shell command.

See : [https://www.diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/](https://www.diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/)

Ok, in my `input-jdbc` case I know I have the `jdbc_password_filepath`, but think other scenarios. 😉

---

<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:** [May 11, 2017, 12:49pm UTC](https://discuss.elastic.co/t/how-to-use-a-dynamic-value-from-shell-in-input-configuration/82208/5 "2017-05-11T12:49:27Z")

</div>

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