# Execute logstash script as batch

**URL:** <https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236>\
**Category:** Logstash\
**Created:** [July 31, 2017, 7:41pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236 "2017-07-31T19:41:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amjad.hussain](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@amjad.hussain](https://discuss.elastic.co/u/amjad.hussain)\
**Post date:** [July 31, 2017, 7:41pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/1 "2017-07-31T19:41:40Z")

</div>

I am using Logstash 5.4.1.  
I need to execute one of my logstash script only once.  
I don't want logstash thread to run in background. I want to use logstash script like a batch.  
Once thread reach end of the file in input file. It should terminate automatically.  
Can someone help me with that?

**_Note: my input is some data file and output is elasticsearch._**

I tried with this syntax. But it didn't work.  
/logstash.bat -f myconf.conf \< testLog.log

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [July 31, 2017, 11:42pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/2 "2017-07-31T23:42:08Z")

</div>

`type testLog.log | logstash.bat -f myconf.conf` will work.

---

<div class="post-metadata">

**Author:** ![amjad.hussain](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@amjad.hussain](https://discuss.elastic.co/u/amjad.hussain)\
**Post date:** [August 1, 2017, 12:52pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/3 "2017-08-01T12:52:04Z")

</div>

It didn't work. Logstash script is not terminated automatically.

This is my script.

input {  
file {  
path =\> "C:/PADS\_ELK/Logstash/logstash-5.4.1/data/input.txt"  
start\_position =\> “beginning”  
}  
}  
filter{  
csv{  
columns =\> [“col1”,“col2”,“col3”]  
separator =\> “,”  
}  
ruby {  
add\_field =\> {  
“col3” =\> “%{[@timestamp]}”  
“updated\_by” =\> “batch”  
}  
code =\> "if event.get('col1').to\_i \< 1000  
event.set('col1','1000')  
end  
if event.get('col2').to\_i \< 10  
event.set('col2','10')  
end"

remove\_field =\> ["message", "path","@version","@timestamp","type","host"]   
}   
}

output {

stdout { codec =\> rubydebug }  
elasticsearch{  
hosts =\> [“localhost:9200”]  
index =\> "my\_index"  
action =\> "update"  
document\_type =\> "my\_type"  
document\_id =\> "%{col1}%{col2}%{col3}"  
doc\_as\_upsert =\> “true”  
}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 1, 2017, 5:05pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/4 "2017-08-01T17:05:25Z")

</div>

If you want to redirect the file to Logstash you need to use a stdin input, not a file input.

---

<div class="post-metadata">

**Author:** ![amjad.hussain](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@amjad.hussain](https://discuss.elastic.co/u/amjad.hussain)\
**Post date:** [August 1, 2017, 6:57pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/5 "2017-08-01T18:57:07Z")

</div>

I need to read one file which has data. Then post it to Elasticsearch.  
Once Logstash reach end of the file, logstash thread should terminate.  
It should not keep running.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [August 1, 2017, 7:18pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/6 "2017-08-01T19:18:35Z")

</div>

Use the stdin input instead of the file input.

Your input should be:

```auto
input { 
    stdin { } 
}

```

Then you will need to use the command that @warkolm posted before.

```auto
type testLog.log | logstash.bat -f myconf.conf 

```

Also, read this topic, it seems to be what you want, maybe it will help: [stop logstash after processing the file.](https://discuss.elastic.co/t/stop-logstash-after-processing-the-file/84959)

---

<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 29, 2017, 7:18pm UTC](https://discuss.elastic.co/t/execute-logstash-script-as-batch/95236/7 "2017-08-29T19:18:39Z")

</div>

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