Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ssh to kill remote process when I interrupt ssh itself?

Tags:

In a bash script I execute a command on a remote machine through ssh. If user breaks the script by pressing Ctrl+C it only stops the script - not even ssh client. Moreover even if I kill ssh client the remote command is still running...

How can make bash to kill local ssh client and remote command invocation on Crtl+c?

A simple script:

#/bin/bash ssh -n -x root@db-host 'mysqldump db' -r file.sql 
like image 959
tkokoszka Avatar asked Dec 01 '08 17:12

tkokoszka


People also ask

Does closing ssh kill process?

As other's have mentioned, once you disconnect from ssh anything running within it is gone.

How do I start a process over ssh and disconnect?

ssh into your remote box. type screen Then start the process you want. Press Ctrl-A then Ctrl-D. This will detach your screen session but leave your processes running.

Which command is stopped after ssh logout?

Using nohup command to Keep Running SSH Sessions After that you can safely log out. With nohup command we tell the process to ignore the SIGHUP signal which is sent by ssh session on termination, thus making the command persist even after session logout.


1 Answers

Eventual I found a solution like that:

#/bin/bash ssh -t -x root@db-host 'mysqldump db' -r file.sql 

So - I use '-t' instead of '-n'. Removing '-n', or using different user than root does not help.

like image 135
tkokoszka Avatar answered Sep 20 '22 06:09

tkokoszka