脚本 - 如果用户退出脚本,则终止SSH连接

时间:2013-08-20 20:01:22

标签: linux shell centos

我有一个在CentOS中运行的shell脚本,代码如下:

#!/bin/sh
dialog --menu "Please choose the server to connect to:" 10 30 15 1 RAS01 2>temp

#OK is pressed
if [ "$?" = "0" ]
then
        _return=$(cat temp)

        # Option 1 selected
        if [ "$_return" = "1" ]
        then
                dialog --infobox "Connecting to server ..." 5 30  ; sleep 2
                telnet XXX.XXX.XXX.XXX
        fi

# Cancel is pressed
else
        exit 5
fi

# remove the temp file
rm -f temp

此脚本背后的想法是,它将在用户登录时自动加载,并且旨在成为连接到系统中不同服务器的防止白痴的方式。因此,如果用户:

,我们希望终止ssh连接
  • 从对话框菜单中选择取消选项
  • 如果用户退出它发起的telnet连接并返回服务器,则运行脚本。

我尝试使用exit 5和exit 1选项,但只退出脚本但不关闭连接。

非常感谢任何帮助。

0 个答案:

没有答案
相关问题