# Logstash output exec executed only once

**URL:** <https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755>\
**Category:** Logstash\
**Created:** [July 19, 2018, 2:15pm UTC](https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755 "2018-07-19T14:15:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mintalicious](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mintalicious](https://discuss.elastic.co/u/mintalicious)\
**Post date:** [July 19, 2018, 2:15pm UTC](https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755/1 "2018-07-19T14:15:59Z")

</div>

Hi,

is there a possibility to run an output exec command only once per logfile and not with every processed document?  
My data comes from CSV-files and I want to delete them after they have been processed by Logstash. I could do this with Logstash's exec output plugin executing an "rm %{path}" as command, but this is done for every row that is in the file and the total number of entries sometimes is \>\> 10.000.  
Maybe there is an internal counter or something like that, which I could check in an if statement, so that it is only executed with the first document?

Thanks in advance 4 your help.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 19, 2018, 5:45pm UTC](https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755/2 "2018-07-19T17:45:38Z")

</div>

It could be done, but that doesn't make it a good idea 🙂

```
    ruby {
        code => '
            if @first.nil?
                event.set("[@metadata][first]", true)
            end
            @first = false
        '
    }
    if [@metadata][first] { [...]
```

---

<div class="post-metadata">

**Author:** ![mintalicious](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mintalicious](https://discuss.elastic.co/u/mintalicious)\
**Post date:** [July 19, 2018, 6:40pm UTC](https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755/3 "2018-07-19T18:40:04Z")

</div>

Thank you very much. That's already **way** faster.  
Is there another way solving this task?

---

<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:** [August 16, 2018, 6:53pm UTC](https://discuss.elastic.co/t/logstash-output-exec-executed-only-once/140755/4 "2018-08-16T18:53:25Z")

</div>

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