我知道当我建立 ssh 连接时我可以运行本地命令,这对于设置终端标题非常有用。
不过,我正在寻找一种在 ssh 连接关闭时运行命令的解决方案。
用法:
>ls
>ssh server2
# want to run something here on the client, this can be done with .ssh/config ProxyCommand
>ls
>exit
# I want to run something on the client, how!?
>ls
答案1
根据 Ubuntuforums 上的 Dill,您可以像这样实现注销脚本:
If you don't already have one, create a .bash_logout file:
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/advanced/node125.html
Here are the contents of my default .bash_logout on an Ubuntu machine and Debian server:
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
他的回答得到的反馈似乎很好。 参考链接
答案2
如果您希望在关闭 SSH 连接后命令继续运行,请使用 nohup 命令 - 请参阅https://superuser.com/questions/143925/what-happens-to-running-processes-when-i-lose-a-remote-connection-to-a-nix-box