# Environment Variable

**URL:** https://discuss.elastic.co/t/environment-variable/109330
**Category:** Beats
**Tags:** filebeat
**Created:** [November 28, 2017, 8:02am UTC](https://discuss.elastic.co/t/environment-variable/109330 "2017-11-28T08:02:54Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![SJN8](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@SJN8](https://discuss.elastic.co/u/SJN8)
#### Post date: [November 28, 2017, 8:02am UTC](https://discuss.elastic.co/t/environment-variable/109330/1 "2017-11-28T08:02:54Z")

</div>

Hi All,

I am trying to make the configuration automate through environment variable described below  
[https://www.elastic.co/guide/en/beats/libbeat/6.0/config-file-format-env-vars.html](https://www.elastic.co/guide/en/beats/libbeat/6.0/config-file-format-env-vars.html)

but same is not working .  
please let know the issue ,

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 28, 2017, 10:26am UTC](https://discuss.elastic.co/t/environment-variable/109330/2 "2017-11-28T10:26:39Z")

</div>

The most common issue people have with environment variables is that they aren't set for the process. How are you setting the environment variables and how are you running the Filebeat process?

If your OS uses systemd have a look at this [post](https://discuss.elastic.co/t/env-variables-in-not-working-in-custom-fields-in-filebeat/101374/4?u=andrewkroh).

---

<div class="post-metadata">

### Author: ![SJN8](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@SJN8](https://discuss.elastic.co/u/SJN8)
#### Post date: [November 28, 2017, 12:26pm UTC](https://discuss.elastic.co/t/environment-variable/109330/3 "2017-11-28T12:26:01Z")

</div>

Hi

PFB the details,

i am setting the env variables by exporting them in .bashrc file .  
and running filebeat with below command ,  
sudo ./filebeat -e -c filebeat.yml -d "publish"

let know for more details .

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 28, 2017, 1:38pm UTC](https://discuss.elastic.co/t/environment-variable/109330/4 "2017-11-28T13:38:00Z")

</div>

`sudo` clears the environment for security purposes. [This is covered in the other post I linked.] Using `sudo -E` will preserve the environment. See [man sudo](https://linux.die.net/man/8/sudo).

Are you planning on using systemd to run Filebeat as a service? What OS are you using?

---

<div class="post-metadata">

### Author: ![SJN8](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@SJN8](https://discuss.elastic.co/u/SJN8)
#### Post date: [November 28, 2017, 2:44pm UTC](https://discuss.elastic.co/t/environment-variable/109330/5 "2017-11-28T14:44:56Z")

</div>

shall i try running without sudo also -E is CLI option for passing arguments .

i am not running filebeat as service as of now but if required i would .

the whole ELK setup is done without systemd .

OS :- CentOS Linux release 7.4.1708 (Core) .

Let know how to proceed .

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 28, 2017, 2:57pm UTC](https://discuss.elastic.co/t/environment-variable/109330/6 "2017-11-28T14:57:44Z")

</div>

> [@SJN8](#):
>
> also -E is CLI option for passing arguments

I was specifically talking about `sudo -E`. In Filebeat `-E` is for passing additional config via the CLI.

To demonstrate the difference to yourself try setting the environment variable then printing it.

```auto
export MY_ENV_VAR=hello
env | grep MY_ENV_VAR
sudo -E env | grep MY_ENV_VAR
sudo env | grep MY_ENV_VAR # Without -E the MY_ENV_VAR variable is dropped from the environment.
```

---

<div class="post-metadata">

### Author: ![SJN8](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@SJN8](https://discuss.elastic.co/u/SJN8)
#### Post date: [November 29, 2017, 5:32am UTC](https://discuss.elastic.co/t/environment-variable/109330/7 "2017-11-29T05:32:57Z")

</div>

Yes , You are right .

Without -E , it is dropping ENV variables .  
Now where i should mention -E is filebeat start CMD .

I am using below command to start filebeat ,

sudo ./filebeat -e -c Filebeat.yml -d "publish" ,

do i need to pass ENV variables , which are used to start the filebeat with -E oprtions .

please suggest the same .

---

<div class="post-metadata">

### Author: ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)
#### Post date: [November 29, 2017, 7:57pm UTC](https://discuss.elastic.co/t/environment-variable/109330/8 "2017-11-29T19:57:51Z")

</div>

> [@SJN8](#):
>
> do i need to pass ENV variables , which are used to start the filebeat with -E oprtions

If you are using the environment variables in your configuration files then you don't need to pass anything in on command line. In you config file you might have something like

```auto
name: ${CUSTOM_NAME}

```

Then on the CLI you would run:

`sudo -E ./filebeat -e -d "publish"`

I recommend testing your config with:

`sudo -E ./filebeat -e -d "config" test config`

This will log the file configuration that is used after evaluating the environment variables.

---

<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: [December 27, 2017, 7:58pm UTC](https://discuss.elastic.co/t/environment-variable/109330/9 "2017-12-27T19:58:16Z")

</div>

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