# Add environment variable to check\_by\_ssh

**URL:** <https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785>\
**Category:** Icinga 2\
**Created:** [October 14, 2020, 9:43am UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785 "2020-10-14T09:43:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [October 14, 2020, 9:43am UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/1 "2020-10-14T09:43:07Z")

</div>

I need to run something like this `LANG=C ls` via check\_by\_ssh and I’m struggling how to define `by_ssh_command` and/or `by_ssh_arguments`. Could anyone provide the correct syntax?

---

<div class="post-metadata">

**Author:** ![yhabteab](https://community.icinga.com/letter_avatar_proxy/v4/letter/y/ac91a4/32.png) [@yhabteab](https://community.icinga.com/u/yhabteab)\
**Post date:** [October 15, 2020, 7:10am UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/2 "2020-10-15T07:10:19Z")

</div>

Hallo @rsx , [here](https://www.netways.de/blog/2016/03/21/check_by_ssh-mit-icinga-2/) are a few examples how to do it right, you can have a look.

I hope this helps you further!

Best,  
Yonas

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [October 15, 2020, 7:19am UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/3 "2020-10-15T07:19:05Z")

</div>

Hi, thanks for that blog entry. However, it does not contain any hints regarding additional environment variables.

---

<div class="post-metadata">

**Author:** ![homerjay](https://community.icinga.com/user_avatar/community.icinga.com/homerjay/32/377_2.png) [@homerjay](https://community.icinga.com/u/homerjay)\
**Post date:** [October 15, 2020, 11:10am UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/4 "2020-10-15T11:10:20Z")

</div>

Hi.

You can add the environment variable as prefix to the ssh-command.

Example:

```auto
vars.by_ssh_command = "LC_ALL=en_US.utf8 /usr/lib/nagios/plugins/your_script"
# Would set LC_ALL to en_US.utf8

```

**Additional notes:**

1. If you use the LC\_ALL, it has to exist on the target system, otherwise it fails
2. SSH-daemon: On the target system (ssh-Daemon), the environment variable has to be accepted.  
Example:

```auto
AcceptEnv LANG LC_* FOO BAR

```

This would accept environment variables named LANG, FOO and BAR and additionally those starting with LC\_

* * *

Hope this helps

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [October 28, 2020, 12:22pm UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/5 "2020-10-28T12:22:16Z")

</div>

```auto
vars.by_ssh_command = "NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script"

```

result in

```auto
Remote command execution failed: sh: NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script: No such file or directory

```

Running the same command directly work as expected:

```auto
ssh 192.168.188.153 -C 'NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/your_script'
OK

```

Any other idea?

---

<div class="post-metadata">

**Author:** ![homerjay](https://community.icinga.com/user_avatar/community.icinga.com/homerjay/32/377_2.png) [@homerjay](https://community.icinga.com/u/homerjay)\
**Post date:** [October 28, 2020, 1:53pm UTC](https://community.icinga.com/t/add-environment-variable-to-check-by-ssh/5785/6 "2020-10-28T13:53:43Z")

</div>

Hi again.

Sorry that it didn’t help.

I tried it with your required environment-variable and it worked:

```auto
vars.by_ssh_command = "NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/whatever_your_scriptname_is.sh"

```

My example script outputs all environment-variables, also:  
NLS\_LANG=AMERICAN\_AMERICA.AL32UTF8

Edit:  
Maybe you could check what arrives at the target-host.  
I captured the executed ssh command and it should look like this:

```auto
NLS_LANG=AMERICAN_AMERICA.AL32UTF8 /usr/lib/nagios/plugins/show_env.sh

```

(But with the correct scriptname and path)

* * *

Greetings.
