I have a bash script that runs a SSH with some commands. If I Ctrl-C the bash script dies, but the ssh session (and its running commands) keep running. How can I effectively send the Ctrl-C to ssh session before dying my bash shell?
This trap will send SIGTERM to all process in the process group when Ctrl-C is pressed:
trap 'kill 0' INT
It's worth noting that the ssh might leave jobs running on the other system, and that you can use a trap in the remote command to handle those as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With