# Logstash - match filename

**URL:** <https://discuss.elastic.co/t/logstash-match-filename/241792>\
**Category:** Logstash\
**Created:** [July 19, 2020, 12:45pm UTC](https://discuss.elastic.co/t/logstash-match-filename/241792 "2020-07-19T12:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elk6](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elk6/32/72282_2.png) [@elk6](https://discuss.elastic.co/u/elk6)\
**Post date:** [July 19, 2020, 12:45pm UTC](https://discuss.elastic.co/t/logstash-match-filename/241792/1 "2020-07-19T12:45:23Z")

</div>

I have two servers. The first one hosts elastic stack. Both servers have a file /var/log/commands.log which is configured in the same way and are being shipped with filebeat to logstash.

Using grok, I tried parsing the data into custom fields using this statement:

```
if [log][file][path] == "/var/log/commands.log" {
grok{
match => { "message" => "*some grok stuff*"
}
}
}

```

Problem is, even though on both servers the file is /var/log/commands.log & they're configured the same - it skips the if statement as if it's false.  
I've noticed that if I ship the logs locally (without filebeat - just do input{file{input =\> "/var/log/commands.log}} ) it works for the local "/var/log/commands.log" file on that machine that hosts logstash.

For reference, this is the full .conf file for logstash: [https://pastebin.com/1QbnAG7G](https://pastebin.com/1QbnAG7G)  
This is how elastic sees the file path: [https://i.imgur.com/5h9HXf2.png](https://i.imgur.com/5h9HXf2.png)

Does anyone why it skips the "if" statement? How to make it filter by name. Thanks ahead!

---

<div class="post-metadata">

**Author:** ![Rom1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rom1/32/49699_2.png) [@Rom1](https://discuss.elastic.co/u/Rom1)\
**Post date:** [August 6, 2020, 4:34pm UTC](https://discuss.elastic.co/t/logstash-match-filename/241792/2 "2020-08-06T16:34:26Z")

</div>

Hi,

In your shared conf, it seems that you use the regexp comparison operator `=~` instead of `==`.  
So logstash thinks that "/var/log/commands.log" is a regex pattern

---

<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:** [September 3, 2020, 4:34pm UTC](https://discuss.elastic.co/t/logstash-match-filename/241792/3 "2020-09-03T16:34:32Z")

</div>

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