用于SSH的Spawn子shell并继续执行程序流程

ins*_*get 4 ssh bash

我正在尝试编写一个shell脚本,根据我的位置(home/campusA/campusB)自动执行某些启动任务.我去大学并在两个不同的校区(因此是校园A /校园B)上课.我的位置取决于我连接的无线网络.出于此脚本的目的,我们可以假设在调用脚本时我将连接到其中一个网络,并且我的脚本根据调用知道我连接到哪个网络iwconfig.

这就是我想要它做的事情:

cat file1 > file2 # always do this, regardless of where I am
if Im at home:
    start tweetdeck, thunderbird, skype

else if Im at campusA:
    activate the login script # I need to login on a webform before I get internet access. 
                              # I have written a script to automate this. 
                              # Wait for this script to finish before doing anything else
    myProg2 & # I want myProg2 running in the background until I shutdown my computer.

else if Im at campusB:
    ssh username@domain # this is the problematic line
    myProg2 & # I want myProg2 running in the background until I shutdown my computer.

start tweetdeck, thunderbird
close the terminal with the "exit" command
Run Code Online (Sandbox Code Playgroud)

问题是campusB的无线网络是在防火墙后面,只有在我成功ssh之后才允许我访问互联网username@domain.成功的ssh之后,我需要保持终端窗口处于活动状态,以便保持互联网访问.如果我关闭终端窗口,我将丢失互联网接入(这是不好的).

当我尝试做的时候ssh username@domain,脚本会停止,因为我没有退出ssh命令.我无法^C摆脱它,这意味着脚本的其余部分永远不会被执行.如果我只是关闭终端窗口以试图终止ssh会话,我也会遇到同样的问题.

一些谷歌搜索带我到subshell,我使用错误或不能用来解决我的问题.那我该如何解决这个问题呢?我很感激任何帮助 - 我已经有一段时间了,我找不到任何有用的东西.如果它有所作为,我宁愿不将我的ssh密码存储在脚本中

此外,和号ssh调用(ssh username@domain &)似乎没有任何好处(任何人都可以解释为什么?)

先感谢您

编辑

我必须澄清,ssh连接必须是活动的,以便我可以访问互联网.因此,当我关闭终端窗口时,我需要ssh连接仍然是活动的.

she*_*ter 7

我有一个循环在6台服务器上的脚本,在后台通过ssh调用.在脚本的一部分中,有一个错误的供应商应用程序; 应用程序没有正确"放开"连接.(在后台使用ssh的脚本的其他部分工作正常).

我发现使用ssh -t -t治愈了这个问题.也许这对你也有帮助.(一个队友在网上发现了这个,我们花了很多时间,我再也没有回过头来看过这篇文章.我们系统的手册页没有暗示这样的事情是可能的)

希望这可以帮助.