# How to modify the value of exported variable in logtash file

**URL:** <https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841>\
**Category:** Logstash\
**Created:** [August 3, 2018, 4:14am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841 "2018-08-03T04:14:27Z")\
**Posts on this page:** 5\
**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:** [August 3, 2018, 4:14am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841/1 "2018-08-03T04:14:27Z")

</div>

I have one variable in shell script and exported it and I want to increase( by 1) the value of this variable in filter block of logstash file .

I have one variable in shell script (ksh file)  
export f=0

logstash file  
f += 1

it's not increased.  
It would be very helpful if someone looks into it.

---

<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 3, 2018, 5:58am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841/2 "2018-08-03T05:58:54Z")

</div>

What you're trying to do just won't work. What underlying problem are you trying to solve? Without background information we won't be able to make any suggestions.

---

<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:** [August 3, 2018, 6:11am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841/3 "2018-08-03T06:11:07Z")

</div>

simply I have exported one variable(flag) in ksh file and intialized by 0.

ksh file  
export flag = 0

now I want to increase the value of flag in filter block of logstash file ..  
because in fliter block I have one condition.

logstash file  
filter  
{  
ruby {  
code =\> "  
if flag == 0  
puts 'one time execution.  
end

flag +=1

"  
}  
}

conclusion is we need to print (puts 'one time execution.) statement once.

hope I explained in better way.

---

<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 3, 2018, 6:24am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841/4 "2018-08-03T06:24:17Z")

</div>

> conclusion is we need to print (puts 'one time execution.) statement once.

Why? What end goal are you trying to reach?

---

<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 31, 2018, 6:24am UTC](https://discuss.elastic.co/t/how-to-modify-the-value-of-exported-variable-in-logtash-file/142841/5 "2018-08-31T06:24:41Z")

</div>

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