当我中断ssh本身时,如何使ssh杀死远程进程? [英] How to make ssh to kill remote process when I interrupt ssh itself?

查看:50
本文介绍了当我中断ssh本身时,如何使ssh杀死远程进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash脚本中,我通过ssh在远程计算机上执行命令.如果用户通过按Ctrl + C断开脚本,它将仅停止脚本-甚至不包括ssh client.而且,即使我杀死了ssh客户端,远程命令仍在运行...

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...

如何使bash杀死Crtl + c上的本地ssh客户端和远程命令调用?

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

一个简单的脚本:

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

推荐答案

最终,我找到了这样的解决方案:

Eventual I found a solution like that:

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

所以-我用'-t'代替'-n'.删除'-n'或使用与root用户不同的用户无济于事.

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

这篇关于当我中断ssh本身时,如何使ssh杀死远程进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆