# Logstash can't read the environment variable

**URL:** <https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949>\
**Category:** Logstash\
**Created:** [October 18, 2021, 5:24am UTC](https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949 "2021-10-18T05:24:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramilbermejo](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@ramilbermejo](https://discuss.elastic.co/u/ramilbermejo)\
**Post date:** [October 18, 2021, 5:24am UTC](https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949/1 "2021-10-18T05:24:32Z")

</div>

Good day everyone!

Need some help here.

On my dev environment, checking the logstash configuration will show this error.

```auto
root@devlogstash:~# /usr/share/logstash/bin/logstash --path.settings /etc/logstash -t
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Sending Logstash logs to /var/log/logstash which is now configured via log4j2.properties
[2021-10-18T05:17:56,572][INFO][logstash.runner] Starting Logstash {"logstash.version"=>"7.9.2", "jruby.version"=>"jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94bcc OpenJDK 64-Bit Server VM 11.0.11+9-Ubuntu-0ubuntu2.20.04 on 11.0.11+9-Ubuntu-0ubuntu2.20.04 +indy +jit [linux-x86_64]"}
[2021-10-18T05:17:59,039][FATAL][logstash.runner] The given configuration is invalid. Reason: Unable to configure plugins: Cannot evaluate `${HSTNM}`. Replacement variable `HSTNM` is not defined in a Logstash secret store or an environment entry and there is no default value given.
[2021-10-18T05:17:59,047][ERROR][org.logstash.Logstash] java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit

```

The variable though was already declared on /etc/default/logstash.

```auto
root@devlogstash:~# cat /etc/default/logstash |grep HSTNM
HSTNM="devlogstash"

```

Please advise on how to fix this error.

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [October 18, 2021, 2:14pm UTC](https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949/2 "2021-10-18T14:14:47Z")

</div>

I don't think /etc/default/logstash is the right place to store an environment variable. `/etc/environment` or `.bashrc` and `.profile` are the places where environment variables are usually stored.  
I took a quick look through the code and the only reference to /etc/default/logstash is in the installation scripts.  
Have you tried doing: `export HSTNM="devlogstash"` before running logstash?

---

<div class="post-metadata">

**Author:** ![ramilbermejo](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@ramilbermejo](https://discuss.elastic.co/u/ramilbermejo)\
**Post date:** [October 19, 2021, 4:58am UTC](https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949/3 "2021-10-19T04:58:42Z")

</div>

@AquaX thank you so much for the info. I'll check it out!

---

<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:** [November 16, 2021, 4:58am UTC](https://discuss.elastic.co/t/logstash-cant-read-the-environment-variable/286949/4 "2021-11-16T04:58:55Z")

</div>

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