Exit/close SSH command?

I have a shell script which executes a long-running Keyboard Maestro macro on a local macOS server. While the script is working as it should, I noticed I am getting error messages in the HA logs due to the 60-second timeout on shell scripts.

I’d like to find a way to modify my script such that it will log in to the local server, execute the KM macro and then immediately close out the SSH session — to take care of everything within a few seconds and avoid the time limit.

When I add exit / background / disown / return commands to the ssh script, it works fine from the command line in the HA Docker container, but when it’s run as an automation within HA, something is making it hang out for the full 60 seconds.

Here is the script in its original form:

ssh -i /config/.ssh/id_ed25519 -o UserKnownHostsFile=/config/.ssh/known_hosts user@local_IP 'source ~/.zshrc && keyboardmaestro XXXXXXX-XXX-XXXX-XXXX=XXXX'

These extra commands help it to exit fine when run directly from the command line:

ssh -fn -i /config/.ssh/id_ed25519 -o UserKnownHostsFile=/config/.ssh/known_hosts user@local_IP 'source ~/.zshrc && keyboardmaestro XXXXXXX-XXX-XXXX-XXXX=XXXX &'

I’d appreciate any suggestions if there’s something obvious I’m overlooking. Thank you!

If you are using the shell_command integration for this, here is a long running Thread on this subject:

I would start at the end of this thread and work backwards.

1 Like

Thank you, @wmaker ! I had read all the other threads regarding SSH timeouts, but all of them were concerned with people butting up against the 60 limit and wanting to extend it further. In my case, I was hoping to come in under the 60 seconds and avoid it altogether.

Luckily, it was one of your replies toward the end of that thread that provided the solution:

https://community.home-assistant.io/t/shell-command-running-into-timeout/249190/19

The “> /dev/null 2>&1 ” means that if the command/script tries to send output to the display or if errors are to printed out, they are instead blocked and not printed out.

Once I added > /dev/null 2>&1 & to the end of my shell script, the errors went away!