Thursday, January 7, 2016

Using ssh to remotely start a process

Use the below format to start a process on a remote server

ssh -n -f user@host "processname > /dev/null 2>&1 &" 
ssh -n -f user@host "sh -c 'cd /whereever; nohup ./whatever > /dev/null 2>&1 &'"

I put the above script into a file and it worked well.

"2>&1 &" need to be added or otherwise will not exit and hangs the ssh command. 2>&1 redirect stdin/stdout/stderr away from your terminal. The  "&" then makes your script go to the background. In production you would of course redirect stdin/err to a suitable logfile