Marius van Witzenburg We fight for our survival, we fight!

16Mar/100

How to get SSH to execute a command in the background on target machine

Posted by mariusvw

If you try to accomplish this directly with SSH... I can tell you, this can be hard to get the job done!

But the solution is quite simple... Create a wrapper around your command which does the job for you.

First prepare your SSH command like:

ssh -ax marius@192.168.3.7 "sh /home/marius/ssh-wrapper > /dev/null 2>&1; exit"

Second is to create the wrapper:

#!/bin/sh
sh /home/marius/run &

You don't have to make the files executable since you prefix it with sh.

This works for me on 2 machines without any problems so far.

Good luck! :-)