# loading scripts only if file exists

**URL:** <https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967>\
**Category:** Zeek\
**Created:** [January 13, 2016, 4:23pm UTC](https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967 "2016-01-13T16:23:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dirk\_Leinenbach](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@Dirk\_Leinenbach](https://community.zeek.org/u/Dirk_Leinenbach)\
**Post date:** [January 13, 2016, 4:23pm UTC](https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967/1 "2016-01-13T16:23:05Z")

</div>

Hi all,

is there a way to @load a script in bro only if the file exists?

My scenario is that I'd like to be able to include configuration data from, e.g., /etc/bro-config.bro. But this script might not exist in all scenarios. Loading it via @load gives an error if the file doesn't exist.

I've tried to use @prefixes to conditionally load scripts, but couldn't figure out exactly where bro would be searching for those scripts.

If there an equivalent for something like "if [-f /etc/bro-config.bro] " ?

Best regards,

Dirk

---

<div class="post-metadata">

**Author:** ![Grant\_Stavely](https://avatars.discourse-cdn.com/v4/letter/g/d78d45/32.png) [@Grant\_Stavely](https://community.zeek.org/u/Grant_Stavely)\
**Post date:** [January 13, 2016, 4:44pm UTC](https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967/2 "2016-01-13T16:44:22Z")

</div>

Hi Dirk,

This just came up last month 🙂

[http://mailman.icsi.berkeley.edu/pipermail/bro/2015-November/009312.html](http://mailman.icsi.berkeley.edu/pipermail/bro/2015-November/009312.html)

And clarified:

[http://mailman.icsi.berkeley.edu/pipermail/bro/2015-December/009324.html](http://mailman.icsi.berkeley.edu/pipermail/bro/2015-December/009324.html)

Grant

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [January 13, 2016, 5:04pm UTC](https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967/3 "2016-01-13T17:04:50Z")

</div>

> I've tried to use @prefixes to conditionally load scripts, but couldn't  
> figure out exactly where bro would be searching for those scripts.

I think that prefixes are probably exactly what you’re looking for. If you add a prefix and then create a file by the right name it will only load it when it finds the file. This is a little tricky with the current setup unfortunately, I didn’t get this setup quite the way I wanted to a number of years ago.

If you write a file named “local.local.bro” to your site/ directory, that script will automatically load if it’s found.

> If there an equivalent for something like "if [-f /etc/bro-config.bro] " ?

Not really.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Dirk\_Leinenbach](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@Dirk\_Leinenbach](https://community.zeek.org/u/Dirk_Leinenbach)\
**Post date:** [January 15, 2016, 3:01pm UTC](https://community.zeek.org/t/loading-scripts-only-if-file-exists/3967/4 "2016-01-15T15:01:02Z")

</div>

Hi Seth,

1. Is “local.local.bro”a hard-coded name that will always work, even without extending @prefixes?
2. If I extend @prefixes inside a plugin script, which directory would be searched? E.g., if I extend prefixes in the following file:

> > > /opt/bro/lib/bro/plugins/Demo\_demo/scripts/Demo/demo/bla.bro  
> > > @prefixes = myprefix
> > > 
> > > while my bro plugin search path is: /opt/bro/lib/bro/plugins
> > 
> > If I understand the documentation correctly, this would search for files named
> > 
> > > myprefix.Demo\_demo.scripts.Demo.demo.bla.bro
> > 
> > Is that correct?

Thanks a lot!

Dirk

---

<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/loading-scripts-only-if-file-exists/3967/5 "2022-05-06T15:43:19Z")

</div>


