# redef script variable from bro command line

**URL:** <https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066>\
**Category:** Zeek\
**Created:** [March 22, 2016, 3:57pm UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066 "2016-03-22T15:57:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Franky](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@Franky](https://community.zeek.org/u/Franky)\
**Post date:** [March 22, 2016, 3:57pm UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066/1 "2016-03-22T15:57:52Z")

</div>

Hi!

This is just a minor problem, but I would still like to understand, why  
it does not work. I am trying to set the log rotation from the command  
line. It works when I use the -e flag:

# bro -r 2009-m57.00.pcap -e "redef Log::default\_rotation\_interval = 20min"

It does not work, if I set the variable at the command prompt:

# bro test.bro -r 2009-m57.00.pcap rotation=20min  
20.0 min  
10.0 min

test.bro:

global rotation = 10min &redef;  
redef Log::default\_rotation\_interval = rotation;

event bro\_init() {  
&nbsp;&nbsp;print(rotation);  
&nbsp;&nbsp;print(Log::default\_rotation\_interval);  
}

I suppose the reason for this is the order in which variables are initialized.

Can someone please explain?

Thanks!

Franky

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 22, 2016, 5:26pm UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066/2 "2016-03-22T17:26:13Z")

</div>

Well, you're setting different things. If I change the 2nd case to  
this:

&nbsp;&nbsp;&nbsp;&nbsp;bro test.bro "Log::default\_rotation\_interval=20min"

... then it works as well.

In your version, when you set "rotation" it changes that global value,  
but at a time when it's old value has already been assigned to  
Log::default\_rotation\_interval. The change will not carry over, as the  
assignment doesn't take place again.

Robin

---

<div class="post-metadata">

**Author:** ![Franky](https://avatars.discourse-cdn.com/v4/letter/f/958977/32.png) [@Franky](https://community.zeek.org/u/Franky)\
**Post date:** [March 23, 2016, 6:38am UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066/3 "2016-03-23T06:38:40Z")

</div>

> \> # bro -r 2009-m57.00.pcap -e "redef Log::default\_rotation\_interval  
> \> = 20min" # bro test.bro -r 2009-m57.00.pcap rotation=20min
> 
> Well, you're setting different things. If I change the 2nd case to  
> this:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;bro test.bro "Log::default\_rotation\_interval=20min"
> 
> ... then it works as well.

That's an even easier solution. I thought I had to use "redef".

> In your version, when you set "rotation" it changes that global value,  
> but at a time when it's old value has already been assigned to  
> Log::default\_rotation\_interval. The change will not carry over, as the  
> assignment doesn't take place again.

Thank you very much! This makes things clear.

Franky

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [March 23, 2016, 2:56pm UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066/4 "2016-03-23T14:56:48Z")

</div>

The command line assignment is essentially a "redef", just shorter for  
convienience.

Robin

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:43pm UTC](https://community.zeek.org/t/redef-script-variable-from-bro-command-line/4066/5 "2022-05-06T15:43:30Z")

</div>


