# How to call a method of ksh file(shell script) from a conf file(logstash file)

**URL:** <https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910>\
**Category:** Logstash\
**Created:** [July 6, 2018, 12:26pm UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910 "2018-07-06T12:26:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashansa1](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@prashansa1](https://discuss.elastic.co/u/prashansa1)\
**Post date:** [July 6, 2018, 12:26pm UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/1 "2018-07-06T12:26:30Z")

</div>

How to call a method of external ksh file(shell script) from a conf file(logstash file).

Shell script (ksh file)  
a.ksh

Test()  
{  
x ="$1"  
if (x \> 10 )  
return x;  
}

Logstash Script (conf file)  
acon.conf

I want to call Test method ( i.e. Test )of above a.ksh file from filter block(of ruby code) of acon.conf conf file

---

<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:** [July 6, 2018, 12:50pm UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/2 "2018-07-06T12:50:41Z")

</div>

This is a shell script question and not a Logstash question.

You can't invoke shell script functions directly from the outside. You'd have to write a.ksh in such a way that running `./a.ksh` or `ksh a.ksh` (possibly with arguments) invokes the Test function.

---

<div class="post-metadata">

**Author:** ![prashansa1](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@prashansa1](https://discuss.elastic.co/u/prashansa1)\
**Post date:** [July 9, 2018, 10:12am UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/3 "2018-07-09T10:12:35Z")

</div>

I am using ruby code in logstash file.  
How to execute shell command from logstash file(conf file ) inside the filter block of ruby code.

---

<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:** [July 9, 2018, 11:25am UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/4 "2018-07-09T11:25:50Z")

</div>

Ruby code executing from a ruby filter is just ordinary Ruby code, it's just that it also has access to the Logstash event currently being processed. There must be a million examples out there of how to run a program from Ruby code.

If you explain what your end goal is we might be able to suggest something that doesn't involve running a shell interpreter for each message (since doing so can improve the event processing rate quite dramatically).

---

<div class="post-metadata">

**Author:** ![prashansa1](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@prashansa1](https://discuss.elastic.co/u/prashansa1)\
**Post date:** [July 9, 2018, 11:29am UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/5 "2018-07-09T11:29:08Z")

</div>

\*\*\* List item\*\*

How to call a method of external ksh file(shell script) from filter block(of ruby code) of conf file(logstash file).

We need to pass an argument (i.e: count) from logstash file (This count variable will be used in Test( ) function ), to ksh file(shell script)'s function (i.e: Test () ).

After it, Test( ) function will return a value that value will be used in logstash file(conf file).

1. Shell script (ksh file)

Test()  
{  
x ="$1"  
y=100  
if (x \> 10 )  
return y;  
}

1. Logstash Script (conf file)

Test 25

---

<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:** [July 9, 2018, 11:33am UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/6 "2018-07-09T11:33:38Z")

</div>

That's not an end goal. You're repeating your description of the means to reach your goal.

---

<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 6, 2018, 11:33am UTC](https://discuss.elastic.co/t/how-to-call-a-method-of-ksh-file-shell-script-from-a-conf-file-logstash-file/138910/7 "2018-08-06T11:33:42Z")

</div>

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