I'm trying to open a tunnel on a remote server from local machine by executing a command remotely via ssh. I'm using sshpass too.sshpass -fpw_file.txt ssh user@host.com 'bash /home/username/do_stuff.sh &'This do_stuff.sh contains just one line:ssh -f -N -L 8888:hostname:9999 user@host &But the call (first command) is not returning. If I put & outside the single quotes, it spawns a process which is not getting killed. Although it is a very small memory leak, it would be good to know if there is a way to do this cleanly.Thanks!
ssh does not return when executing remote process in bg
ssh;remote;ssh tunneling;background process
Redirect the i/o streams to null. BG processes with open descriptors can cause SSH to not close.sshpass -fpw_file.txt ssh user@host.com 'bash /home/username/do_stuff.sh &> /dev/null < /dev/null &'Explanation&> /dev/null takes stdout and stderr and redirects it to null< /dev/null takes stdin and redirects it to null& at the end sends the process to the background.