开发者

Preferred way to terminate `ssh -N` in background using bash?

开发者 https://www.devze.com 2023-02-11 22:17 出处:网络
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 detach

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 jobs -p, but is there a better way to do that?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消