Preferred way to terminate `ssh -N` in background using bash?
I've started ssh -N <somehost> &
in a bash script (to create a tunnel), and the connection persists after the script ends, and I see with ps
that the ssh pro开发者_运维知识库cess has detached.
I am currently killing the background job with kill
, but is there a better way to do that?jobs -p
Do you manually end your script?
if so:
Try to catch the QUIT signal (or others) inside your script (use the
trap builtin command I think). Then kill ssh.
else:
Kill ssh at the end of your script.
精彩评论