UnRAID Shutdown with Script

Hello, I would like to shut down unRAID via openHAB.
For this I have installed sshpass on the Raspberry.

If I now execute the command via SSH, unRAID shuts down.
I have now packed the command in a .sh file, however, this does not work. Do I have an error somewhere?


Switch unraidshutdown_RUN {channel="exec:command:unraidshutdown:run"}


Thing exec:command:unraidshutdown "Unraid Shutdown" [command="/etc/openhab/scripts/AZ_UnRAID_Shutdown.sh", interval=0 , timeout=10, autorun=false]

.sh File

sshpass -p PASSWD ssh root@ poweroff

The file is also whitelisted.

Better to set up ssh certificates.

When called from the command line or when called from openHAB? If it doesn’t work from the command line it’s never going to work anywhere. If it works from the command line, what happens when you run it under the openhab user?

Note that when it’s run from openHAB, ssh and sshpass might not be in the path. Use the fill path to those commands.

The command exactly as it appears in the Thing config is the only thing that needs to be whitelisted.

Do you have a link with instructions? Have not found anything.

From the command line. When I am logged in to openHAB via SSH (openhabian) and send the command, it works.
But when I want to run the command as user openhab it does not work.
I think this is the problem.
How can I give the user openhab the permission to do this?

I think that should be correct. The entry looks like this:


I have now tried again with the “executeCommandLine” command in a rule. Here I get the error that there is no authorization.


In Log it looks like this:

2023-03-14 12:04:46.376 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Error occurred when executing commandLine '[/etc/openhab/scripts/AZ_UnRAID_Shutdown.sh]'
java.io.IOException: Cannot run program "/etc/openhab/scripts/AZ_UnRAID_Shutdown.sh": error=13, Keine Berechtigung

The permissions of the .sh file look like this:



I changed the permission, now I don’t get any error in the log either.
However, the server is not shut down.


Search Google or your engine of choice for “ssh certificate” . DuckDuckGo shows six different tutorials on the first page of results.

Well, you’ve eliminated OH as the source of your problem. You’ll have to debug the UnRAID and your script to find the root cause of the problem.

use the version that returns loggging output and write that logging to your openhab.log file

var ScriptResponse = executeCommandLine(Duration.ofSeconds(5), "/etc/openhab/scripts/AZ_UnRAID_Shutdown.sh")

I think the problem is that the ssh process insists on prompting for the key fingerprint of the server that you want to login. This also will be the case when certificates will be used…
This should be the result of the returned output of executeCommandLine.

To avoid this you may modify the ssh command:

sshpass -p PASSWD ssh -o "StrictHostKeyChecking=no" root@ poweroff

This will ignore the fingerprint of the remote host.
If you would like to continue with secure connections you would have to make sure that the openhab user has a .ssh sub-directory in its home directory and a file known_hosts that contains a line with the fingerprint of the remote host.

This is exactly where the error lay. After the fingerprint was ignored, the server also shuts down via openHAB.
Thank you for your help.

1 Like