# No output - bash script calling C program via SSH

**URL:** <https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461>\
**Category:** Scripts & Rules\
**Tags:** ssh, bash\
**Created:** [November 17, 2020, 9:04pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461 "2020-11-17T21:04:47Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 17, 2020, 9:04pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/1 "2020-11-17T21:04:47Z")

</div>

**Platform information:**

- Hardware: Synology DS215j, 800MHz, 2 core, 512MB
- OS: DSM 6.2.3-25426 Update 2
- Java Runtime Environment: Java8 installed
- openHAB version: 4.2.7

**Issue of the topic:**  
**What I want to do:**

- Create a weather station
- Read data from a Raspberry Pi
- Based on this tutorial: [Source](https://tutorials-raspberrypi.de/raspberry-pi-wetterstation-bauen-openhab2/)

**What works so far:**

- basicaly everything except the display of the actual vaule

**This is different to the turorial**  
Things configuration:

```
Thing exec:command:weatherstation_temperature "Temperatur" [command="ssh pi@192.168.178.33./weatherSensor temp", transform="REGEX((.*?))", interval=60, timeout=10, autorun=true]
Thing exec:command:weatherstation_humidity "Luftfeuchtigkeit" [command="/volume1/SmartHome/openHAB/conf/scripts/weather.sh", transform="REGEX((.*?))", interval=60, timeout=10, autorun=true]

```

Tried two ways, one direct with ssh and one by using a bash script

```
#!/bin/bash
out=$(ssh pi@192.168.178.33 ./weatherSensor temp)
echo $out

```

So as I sad, all the Things, Items, Graphs are working, but the actual number (e.g. temperature) is not displayed.  
If I execute the script by hand it will return the result (e.g. 22.17)

Sadly the log file has no recent entrys, and I was not able to figure out why it stopped filling it.

I hope I included all the information needed, otherwise please ask.

Thank you for your efforts.

Kind regards, nuTux

---

<div class="post-metadata">

**Author:** ![anon63824877](https://community.openhab.org/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@anon63824877](https://community.openhab.org/u/anon63824877)\
**Post date:** [November 17, 2020, 9:15pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/3 "2020-11-17T21:15:24Z")

</div>

Whats your item configuration?

You only show the thing. However Things are not displayed in the sitemap. You have to link your things to items. However I assume you did that since you are saying that

> [@nuTux](#):
>
> all the Things, Items, Graphs are working

* * *

For your items: Try a label transormation.As a example see my definition for a temperature item:

```csv
Number RPi2Helper_Temperatur "CPU Temperatur [%.1f °C]"   

```

* * *

Another idea is to get the measurements via a cronjob on the maschine you are executing the command on (192.168.178.33). See this example:

script:

```auto
#!/bin/bash

OHIP="192.168.178.108"

send(){
    curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$state" "http://$OHIP:8080/rest/items/$item/state"
}

item="RPi2Helper_Temperatur"
state=$(vcgencmd measure_temp | sed 's/temp=//' | sed "s/'C//" )
send

```

cronjob which runs the script once per minute and sends the temp to the OH server:

```auto
pi@rpi2helper:~ $ crontab -l
* * * * * /home/pi/OpenHAB-Config/scripts/RPi2/Status\ an\ OpenHAB\ senden/status2OpenHAB.sh

```

I recommend this method since you are not getting any errors if the OH server can’t connect to 192.168.178.33. Furthermore you dont have to deal with SSH Keys. (I assume you have SSH Keys, right? Otherwise your implemented solution can’t work)

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 17, 2020, 9:19pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/4 "2020-11-17T21:19:29Z")

</div>

There is a space missing in the first thing between the IP and the command.  
Are you sure that the ssh command is executed as it is being started as user openhab and needs to have the openhab public key iimported into authorized\_keys of user pi while I assume that your manual test was executed as user pi.  
Besides that the command is in the whitelist ?  
Any error message in the openhab.log file ?

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 17, 2020, 9:35pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/5 "2020-11-17T21:35:22Z")

</div>

Ok so first of all, thats what I’m seeing.

 ![screen](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/6/4/64ab69543db28cd24c39e882c46aff39856afcfc.png)

Thats why I assume, that everything else is working (since I got all of it from a tutorial).

Is the time running the script not defined by the interval=60 command in the Thing?

So this is the item configuration

```
Group Weatherstation_Chart (System, Charts)
Number Weatherstation_Chart_Period "Periode" (System)
Number Weatherstation_Temperature "Temperatur [%.1f °C]" <temperature> (Weatherstation_Chart) 
Number Weatherstation_Humidity "Luftfeuchtigkeit [%.1f %%]" <humidity> (Weatherstation_Chart)
Number Weatherstation_Pressure "Luftdruck [%.1f hPa]" <pressure> (Weatherstation_Chart)
 
String temperature_out { channel="exec:command:weatherstation_temperature:output" }
String humidity_out { channel="exec:command:weatherstation_humidity:output" }
String pressure_out { channel="exec:command:weatherstation_pressure:output" }

```

This the rule

```
rule "Weatherstation Temperature"
	when
		Item temperature_out received update
	then
		Weatherstation_Temperature.postUpdate(
			( ( Float::parseFloat(temperature_out.state.toString) as Number ) * 10 ) / 10
		)
end

rule "Weatherstation Humidity"
	when
		Item humidity_out received update
	then
		Weatherstation_Humidity.postUpdate(
			( ( Float::parseFloat(humidity_out.state.toString) as Number ) * 10 ) / 10
		)
end
												    
rule "Weatherstation Pressure"
	when
		Item pressure_out received update
	then
		Weatherstation_Pressure.postUpdate(
			( ( Float::parseFloat(pressure_out.state.toString) as Number ) * 10 ) / 10
		)
end

```

As I said before, the log has no entries since yesterday… could I have turned it off accidentally?

Where can I check the whitlist of the command?

[edit]

- the space was a copy error, sorry
- yes the ssh keys are working
- files are owned by openhab user and ar executable  
[\edit]

Regards nuTux

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 17, 2020, 9:48pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/6 "2020-11-17T21:48:58Z")

</div>

The whitelist is the file /etc/openhab2/misc/exec.whitelist  
In case there is no entry for your command in the whitelist and no entry in the log file then it looks like the command is not executed.

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 17, 2020, 9:57pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/7 "2020-11-17T21:57:26Z")

</div>

Ok, so I found the log file which is updated regularly.  
It seems that on the synology install, the whole folder structure is quite different…

```
2020-11-17 22:52:26.448 [WARN] [ng.exec.internal.handler.ExecHandler] - Tried to execute '/volume1/SmartHome/openHAB/conf/scripts/weather.sh', but it is not contained in whitelist.
2020-11-17 22:52:26.449 [WARN] [ng.exec.internal.handler.ExecHandler] - Tried to execute '', but it is not contained in whitelist.
2020-11-17 22:52:26.488 [WARN] [ng.exec.internal.handler.ExecHandler] - Tried to execute 'ssh pi@192.168.178.33 ./weatherSensor temp', but it is not contained in whitelist.

```

So it is a problem with the white liste.

Now I just need to find the misc folder…

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 17, 2020, 9:57pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/8 "2020-11-17T21:57:36Z")

</div>

You also may try to add the path to the executable ( ssh ) in the exec command line as well as in the bash script. This would help in case the exec environment does not have a search path included.

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 17, 2020, 9:58pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/9 "2020-11-17T21:58:50Z")

</div>

> [@nuTux](#):
>
> Now I just need to find the misc folder…

I would expect it next to the items, things folder.

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 17, 2020, 10:24pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/10 "2020-11-17T22:24:02Z")

</div>

Hm, there was nothing… so I created it.

But I couldn’t find any information about how this whitlist file is organized…

to I just add the command

```
ssh

```

path to command

```
/bin/ssh

```

full command

```
ssh pi@192.168.178.33 ./weatherStation temp

```

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 18, 2020, 6:21am UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/11 "2020-11-18T06:21:01Z")

</div>

> [@nuTux](#):
>
> Hm, there was nothing… so I created it.

so it is. for security reasons there is no default content / file available.

> [@nuTux](#):
>
> But I couldn’t find any information about how this whitlist file is organized…

The documentation of the binding at the top in the binding-configuration section

> **[Exec - Bindings](https://www.openhab.org/addons/bindings/exec/#binding-configuration)**
>
> This binding integrates the possibility to execute arbitrary shell commands.

states:

> For security reasons all commands need to be whitelisted. Allowed commands need to be added to the misc/exec.whitelist file in the configuration directory. Every command needs to be on a separate line.
> 
> Example:
> 
> /bin/echo “Hello world!”  
> /usr/local/bin/apcaccess status  
> php ./configurations/scripts/script.php %2$s
> 
> Linux: Note that the commands are executed in the context and with the privileges of the process running the Java Virtual Machine. On a Linux system the system user openhab needs to have the privileges needed to execute your intended command. It is advised to test the correct operation of the command in the scope of the openhab user on the command line first:
> 
> sudo -u openhab
> 
> It is not advised to run the virtual machine as superuser/root.

I think it can’t be more complete and it is in the right place - the doc of the binding. Even not necessary to search in the forum which also delivers a set of hits:

> **[Bevor Sie zur Google Suche weitergehen](https://www.google.com/search?channel=fs&client=ubuntu&q=site%3Acommunity.openhab.org%2Bsolved%2Bwhitelist%2Bexec%2Bbinding)**

Could be that you didn’t find anything in case you misspelled ( missing e ) it

> [@nuTux](#):
>
> whitlist

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 18, 2020, 6:23pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/12 "2020-11-18T18:23:27Z")

</div>

Hm ok, so I thought it didn’t work with the examples which were provided in the doc…

The log file always tells me

```
Tried to execute '/bin/echo '42.2'', but it is not contained in whitelist.

```

So could it be that on the Syonology install the directories are different?  
Is there a way to find out where it looks for the whiteliste file?

I know placed the misc folder in the conf folder which seems to make sense, but all the commands I tried it told me that it was not present in the whiteliste…

```
/bin/ssh pi@192.168.178.33 ./weatherSensor temp
/volume1/SmartHome/openHAB/conf/scripts/weather.sh
/bin/echo '42.2'

```

I thought the echo example should work, but not even that…

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 19, 2020, 6:52am UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/13 "2020-11-19T06:52:28Z")

</div>

What is the path of the directory where you put your rules into ?  
What is the path of the directory where you put the exec.whitelist into ?

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 19, 2020, 6:13pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/14 "2020-11-19T18:13:30Z")

</div>

So rules are:  
/volume1/SmartHome/openHAB/conf/rules/weatherstation.rules

and whiteliste

/volume1/SmartHome/openHAB/conf/misc/exec.whitelist

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [November 19, 2020, 8:33pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/15 "2020-11-19T20:33:34Z")

</div>

I would expect that this fine.  
How did you create, edit the file ? Did you create/edit it with a windows editor or in a linux environment ? Could be that it is a problem of line feeds/carriage return which are different / depending on the OS.

---

<div class="post-metadata">

**Author:** ![nuTux](https://community.openhab.org/letter_avatar_proxy/v4/letter/n/7ab992/32.png) [@nuTux](https://community.openhab.org/u/nuTux)\
**Post date:** [November 19, 2020, 8:34pm UTC](https://community.openhab.org/t/no-output-bash-script-calling-c-program-via-ssh/108461/16 "2020-11-19T20:34:49Z")

</div>

I created it, logged in as the user which will execute it (openhab). Directly with vim on the linux system (synology NAS). So I think that should be fine…
