在远程系统上运行SSH脚本 - 退出

时间:2014-05-27 08:32:36

标签: linux shell ssh sysadmin

我使用以下语法在远程Linux系统上运行本地shell脚本:

ssh -o PubKeyAuthentication=yes -o PreferredAuthentications=publickey username@servername 'bash -s' < localscript.sh

我的脚本末尾没有包含任何退出命令,但是当脚本完成后,服务器的ssh连接似乎会自动关闭。我的问题是;我是否需要在脚本中包含任何退出说明,以确保在服务器端干净地终止会话?

非常感谢提前

2 个答案:

答案 0 :(得分:0)

你没有。 shell遇到的最后一个信息是'localscript.sh'的文件结尾。这将导致所有bash和ssh进程终止。

答案 1 :(得分:0)

不,Bash在脚本结束时终止。最后一个命令的退出代码成为Bash的退出代码。

相关问题