# Filebeat config - USER system env variable

**URL:** https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428
**Category:** Beats
**Tags:** filebeat
**Created:** [May 13, 2020, 12:03pm UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428 "2020-05-13T12:03:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Johny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johny/32/68242_2.png) [@Johny](https://discuss.elastic.co/u/Johny)
#### Post date: [May 13, 2020, 12:03pm UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428/1 "2020-05-13T12:03:27Z")

</div>

Hello, i am trying read logs from currently logged user folder. In filebeat config i have:  
paths:  
`- /home/${USERNAME}/logs/foo.log`, this does not even compile. But it work when i hardcode name like this:  
paths:  
`- /home/${USERNAME:foo}/logs/foo.log`, but i need this path to be dynamically allocated.

There are no logs in /var/log/filebeat/filebeat.log

 ![filebeat](https://us1.discourse-cdn.com/elastic/original/3X/e/f/ef00039eb8f000119d28a02b8ed606fffc1f6b5e.png)

---

<div class="post-metadata">

### Author: ![Andre\_Letterer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andre_letterer/32/42248_2.png) [@Andre\_Letterer](https://discuss.elastic.co/u/Andre_Letterer)
#### Post date: [May 30, 2020, 10:42pm UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428/2 "2020-05-30T22:42:38Z")

</div>

Hi Johny,

Welcome to the discuss forum.  
Now if you give out the environment variables on a linux system:

```auto
env | grep USER | sort

```

I think you should find out that the variable should be `USER`. Variable `USERNAME` only exists on Windows systems as far as I know.

```auto
- /home/${USER}/logs/foo.log

```

Apart from that I would like to know what exactly you are trying to accomplish.  
Do you want to u read dynamically through all your user folders?  
Something like

```auto
/home/usera/logs/foo.log
/home/userb/logs/foo.log

```

and if you add a new user `userc` it should start to read this one `/home/userc/logs/foo.log` as well?

If this what you want to do?

Because with that at the moment I assume it will log only one folder.

---

<div class="post-metadata">

### Author: ![Johny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johny/32/68242_2.png) [@Johny](https://discuss.elastic.co/u/Johny)
#### Post date: [June 2, 2020, 7:49am UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428/3 "2020-06-02T07:49:42Z")

</div>

Hello and thank you for your reply.  
Use case is... When userA start using program. It will creates:  
/var/log/program- **userA** /foo.log.  
Then second user loggin to the machine and it will creates new logs in:  
/var/log/app- **userB** /foo.log.  
I need filebeat config that automatically assign variables of currently logged users to the path:  
/var/log/app- **{USER}** /foo.log, so I don't have to manualy set up and hardcode users to each machine.  
I can tail path like this /var/log/app- \* /\*.log. But it's not look like the best practice. Besides this logs everything.

To find user variable I used env command and when i use it in cd path/to/{variable}/folder, it works fine.

---

<div class="post-metadata">

### Author: ![Andre\_Letterer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andre_letterer/32/42248_2.png) [@Andre\_Letterer](https://discuss.elastic.co/u/Andre_Letterer)
#### Post date: [June 11, 2020, 9:26pm UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428/4 "2020-06-11T21:26:12Z")

</div>

Hi Johny,

maybe it is

[https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#input-paths](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#input-paths)

Globbing depends on slashes like is documented here: [https://golang.org/pkg/path/filepath/#Glob](https://golang.org/pkg/path/filepath/#Glob)

If you want you maybe could disable recursive globbing:  
[https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#recursive\_glob](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#recursive_glob)

So basically it the actual best practice like that:

```auto
filebeat.inputs:
- type: log
  recursive_glob.enabled: false
  paths:
    - /var/log/program-*/foo.log

```

Now apart from that let my try to tackle your last comment  
If I understand you correctly you maybe have following paths like e.g.:

```auto
/var/log/program-john/foo.log
/var/log/program-jessy/foo.log
/var/log/program-retrieve/foo.log

```

And what you want is automatically identify the first 2 paths as being paths from users john and Jessy and it should ingest these ones, but not the third one, which is not a user?

Is this exactly what you are trying to do?

---

<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: [July 9, 2020, 9:26pm UTC](https://discuss.elastic.co/t/filebeat-config-user-system-env-variable/232428/5 "2020-07-09T21:26:14Z")

</div>

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