# Command path different between machines

**URL:** <https://community.icinga.com/t/command-path-different-between-machines/8556>\
**Category:** Icinga 2\
**Created:** [October 31, 2021, 12:26am UTC](https://community.icinga.com/t/command-path-different-between-machines/8556 "2021-10-31T00:26:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkuenning](https://community.icinga.com/letter_avatar_proxy/v4/letter/g/53a042/32.png) [@gkuenning](https://community.icinga.com/u/gkuenning)\
**Post date:** [October 31, 2021, 12:26am UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/1 "2021-10-31T00:26:23Z")

</div>

On Icinga2 v2.12.3, I’m writing a CheckCommand for a plugin that I want to execute on a number of machines. The problem is that they run different distros, and the plugin I want lives in a distro-specific place: PluginDir on some and LocalPluginDir on others.

I started with something like this:

```auto
Object CheckCommand "eth" {
    if (vars.distro == "distro1") {
        command = [PluginDir + "/check_eth"]
    } else {
        command = [LocalPluginDir + "/check_eth"]
    }

```

That didn’t work, I guess because vars.distro wasn’t being evaluated on a per-host basis. I then wasted a couple of hours trying various things, without success. I finally succeeded with a truly ugly shell-based hack:

```auto
    command = ["sh", "-c", "if [ -x " + LocalPluginDir + "/check_eth]; then " + LocalPluginDir + "/check_eth -b $$*; else " + PluginDir + "/check_eth -b $$*; fi" ]

```

That has two problems. The first is that it’s just horrible. The second is the “-b” after check\_eth; for some reason the first argument in the (sorted) argument list isn’t getting passed. I think that’s probably a bug; I verified that the following produces the expected results, with the “-b” switch included:

```auto
    command = ["/bin/echo"]

```

Anyway, so I’ve figured out a solution (modulo the bug). But is there a better way? (Yes, I’ve considered putting a symlink to the plugin in LocalPluginDir for the machines that use PluginDir, but that’s painful.)

---

<div class="post-metadata">

**Author:** ![leeclemens](https://community.icinga.com/user_avatar/community.icinga.com/leeclemens/32/1283_2.png) [@leeclemens](https://community.icinga.com/u/leeclemens)\
**Post date:** [October 31, 2021, 1:52pm UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/2 "2021-10-31T13:52:19Z")

</div>

I don’t have `LocalPluginDir` defined anywhere, but on each host I have `PluginContribDir` defined in `/etc/icinga2/constants.conf`. This points to the location applicable for that specific host.

---

<div class="post-metadata">

**Author:** ![gkuenning](https://community.icinga.com/letter_avatar_proxy/v4/letter/g/53a042/32.png) [@gkuenning](https://community.icinga.com/u/gkuenning)\
**Post date:** [November 1, 2021, 5:04am UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/3 "2021-11-01T05:04:53Z")

</div>

Thanks! I guess that’d work (with a bit of adaptation), but it’s about the same as creating a symlink: it requires separate configuration on every host. I was hoping for something that could be done entirely on the master (which my shell hack accomplishes, but what a hack).

---

<div class="post-metadata">

**Author:** ![leeclemens](https://community.icinga.com/user_avatar/community.icinga.com/leeclemens/32/1283_2.png) [@leeclemens](https://community.icinga.com/u/leeclemens)\
**Post date:** [November 1, 2021, 1:21pm UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/4 "2021-11-01T13:21:04Z")

</div>

It may be worth evaluating why your plugins are installed in different locations on every host in the first place. There are several config management tools out there too that can make it pretty simple to update `constants.conf`.

---

<div class="post-metadata">

**Author:** ![gkuenning](https://community.icinga.com/letter_avatar_proxy/v4/letter/g/53a042/32.png) [@gkuenning](https://community.icinga.com/u/gkuenning)\
**Post date:** [November 1, 2021, 10:06pm UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/5 "2021-11-01T22:06:30Z")

</div>

I’m pretty sure I already explained that the reason the plugins are in different places is because the machines run different distros. I would hope that it’s obvious that there are reasons for that fact.

---

<div class="post-metadata">

**Author:** ![gkuenning](https://community.icinga.com/letter_avatar_proxy/v4/letter/g/53a042/32.png) [@gkuenning](https://community.icinga.com/u/gkuenning)\
**Post date:** [November 7, 2021, 12:34am UTC](https://community.icinga.com/t/command-path-different-between-machines/8556/6 "2021-11-07T00:34:42Z")

</div>

Sometimes our brains fade. My shell hack be better if I had simply remembered PATH:

```auto
    command = ["sh", "-c", "PATH=" + LocalPluginDir + ":" + PluginDir + ":$$PATH check_eth -b $$*"]

```

which is still ugly but not _as_ ugly.

(Still no clue why the -b is necessary, though.)
