Hello and welcome to Super User.
ssh -L 8888:localhost:8888 [email protected], your script founds itself on the remote server.
You can pass the flags
-f is for fork into background and
-N is run no command).
Then, after the tunnel is established, your script resumes execution on the next line on your machine.
The downside is that the
ssh connection will remain in the background even after your script is finished.
A workaround is ditching the
-N flag and execute
sleep 10 on the remote server:
ssh -f -L 8888:localhost:8888 [email protected] sleep 10
This way, if the tunnel is not used, either when
run_website.sh terminates or after 10 seconds if the script won’t use the tunnel (i.e. fails for some reason), it will disconnect automaticaly.
This obviously assumes that
run_website.sh uses the tunnel.
If you don’t care about automatically terminating the tunnel, then go ahead and simply use
ssh -fN -L 8888:localhost:8888 [email protected]
You can kill the
ssh process later if you need.