Solved : Two identical exec commands ( run ssh ) behave differently

Good Morning !

I use openhab4 in docker at a Synology NAS.

  • rule wolNas2 or wolNas3 3 should shut down the server 2 or 3 via ssh

  • wolNas2 does this.

  • wolNas3 reports “Host key verification failed.”

  • the keys are in /openhab/.ssh

  • on the command line in docker the command:
    ssh -i /openhab/.ssh/id_rsa_nas3 root@123.123.123.123 -p 123 ‘nohup shutdown -h now > /dev/null 2>&1 &’
    is executed correctly for nas3.

  • I struggle : why at cml but not in the rule?

I hope somebody can point me to right direction …

// exec.things:
Thing exec:command:ssh	[ command="ssh -i %2$s >/dev/null && echo ok || echo nok", interval=0, autorun=false ]
exec.whitelist:
ssh -i %2$s >/dev/null && echo ok || echo nok
// wol.items:
Switch	wolNas2			"INIGMANAS2"				<wol>	(gWol)
Switch	wolNas3			"INIGMANAS3"				<wol>	(gWol)
String	sshWolRes		"INIGMANAS [%s]"
Switch	sshWolRun 		{channel="exec:command:ssh:run", autoupdate="false"}	// state of the execution, is running or finished
String	sshWolArgs 	    {channel="exec:command:ssh:input"} 						// Arguments to be placed for '%2$s' in command line
String	sshWolOut 		{channel="exec:command:ssh:output"}						// Output of command line execution
// wol.rules
rule "sdNas2"
when
	Item wolNas2 changed to OFF
then
	if (nh_nas2.state == ON) {
		logInfo("sshWolArgs.sendCommand","arg: " + "/openhab/.ssh/id_rsa_nas2 root@123.123.123.122 -p 122 'nohup shutdown -h now > /dev/null 2>&1 &'")
		sshWolArgs.sendCommand("/openhab/.ssh/id_rsa_nas2 root@123.123.123.122 -p 122 'nohup shutdown -h now > /dev/null 2>&1 &'")
		Thread::sleep(500) 					// Adjust delay if needed
		sshWolRun.sendCommand(ON) 			// Trigger execution after setting arguments
	}
end

rule "sdNas3"
when
	Item wolNas3 changed to OFF
then
	if (nh_nas3.state == ON) {
		logInfo("sshWolArgs.sendCommand","arg: " + "/openhab/.ssh/id_rsa_nas3 root@123.123.123.123 -p 123 'nohup shutdown -h now > /dev/null 2>&1 &'")
		sshWolArgs.sendCommand("/openhab/.ssh/id_rsa_nas3 root@123.123.123.123 -p 123 'nohup shutdown -h now > /dev/null 2>&1 &'")
		Thread::sleep(500) 					// Adjust delay if needed
		sshWolRun.sendCommand(ON) 			// Trigger execution after setting arguments
	}
end

rule "sshWol_complete"
when
	Item sshWolRun changed from ON to OFF
then
	logInfo("ssh command exec", "Script has completed.")
end

rule "sshWol_results"
when
	Item sshWolOut received update
then
	logInfo("ssh command exec", "Raw result:" + sshWolOut.state.toString )
	sshWolRes.postUpdate(sshWolOut.state.toString)
end

Sometimes you only have to write down a problem, and during doing this you have to think it over.
The reason was simple.
At the first ssh access, you can add the new host / server to the “known hosts file”.
I did it. But for NAS3 I was logged in a as root to openhab an the root’s “known host file” was updated, not user openhab’s file.