Skip to main content

Running [ # sshpass -fpw_file.txt ssh user@host 'bash /path/to/script.sh &' ] does not return when executing remote process in bg

Source Link
Nirmal
  • 143
  • 1
  • 5

Running [ # sshpass -fpw_file.txt ssh user@host 'bash /path/to/script.sh &' ] does not return

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 [email protected] '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!