BASH产卵子shell为SSH并继续程序流程 [英] BASH spawn subshell for SSH and continue with program flow

查看:134
本文介绍了BASH产卵子shell为SSH并继续程序流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个自动根据我的位置(家/ campusA / campusB)某些启动任务的shell脚本。我去大学上课在两个不同的校区(因此campusA / campusB)。我的位置是由无线网络,我连接到​​确定。对于这个脚本的目的,我们可以假设,我将连接到这些网络之一,当脚本调用,我的脚本知道我连接到基于对的iwconfig

I'm trying to write a shell script that automates certain startup tasks based on my location (home/campusA/campusB). I go to University and take classes in two different campuses (hence campusA/campusB). My location is determined by which wireless network I'm connected to. For the purposes of this script, we can assume that I will be connected to one of these networks when the script is called and my script knows which one I'm connected to based on a call to 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

问题是,campusB的无线网络是防火墙,授予我上网之后,只有我通过成功SSH用户名@域名后面。一个成功的SSH之后,我需要保持终端窗口活动以保持保持网络连接。如果我关闭终端窗口,我失去互联网连接(这是不好的)。

The problem is that campusB's wireless network is behind a firewall, which grants me internet access ONLY after I successfully ssh by username@domain. After a successful ssh, I need to keep the terminal window active in order to hold keep the internet access. If I close the terminal window, I lose internet access (this is bad).

当我尝试做只是 SSH用户名@域名,脚本将停止,因为我不退出 SSH 命令。我不能 ^ C 出来,这意味着脚本的其余部分永远不会执行。我也有同样的问题,如果我只是关闭终端窗口,企图杀死 SSH 会话。

When I try doing just ssh username@domain, the script stops because I don't exit the ssh command. I can't ^C out of it, which means that the rest of the script is never executed. I also have the same problem if I just close the terminal window in an attempt to kill the ssh session.

一些谷歌搜索给我带来了 子shell ,该我或者使用错误的或者不能用它来解决我的问题。所以,我应该怎么去解决这个问题呢?我倒是AP preciate任何帮助 - 我已经在这一段时间现在我无法找到任何有用的。如果它的确与众不同,我宁愿不储存我的 SSH 密码在脚本

Some googling brought me to subshell, which I'm either using wrong or can't use to solve my problem. So how should I go about solving this problem? I'd appreciate any help - I've been at this for a while now and am unable to find anything helpful. If it makes a difference, I'd rather not store my ssh password in the script

此外,ampersanding的 SSH 调用( SSH用户名@域名和放大器; )似乎并没有做任何良好的(任何人都可以解释为什么吗?)

Further, ampersanding the ssh call (ssh username@domain &) doesn't seem to do any good (can anyone explain why?)

感谢您提前

修改

我必须澄清,即SSH连接必须激活为了让我能够访问Internet。因此,当我关闭终端窗口,我需要ssh连接仍然是活动的。

I must clarify, that the ssh connection has to be active in order for me to have internet access. Thus, when I close the terminal window, I need the ssh connection to still be active.

推荐答案

我有这样的循环在6个服务器,通过在后台调用SSH的脚本。在脚本的第一部分,有一个错误行为的供应商的应用程序;应用程序没有'放手'的连接正常。 (在后台用ssh脚本的其他部分工作得很好)。

I had a script that looped on 6 servers, calling via ssh in the background. In 1 part of the script, there was a mis-behaving vendor application; the application didn't 'let go' of the connection properly. (other parts of the script using ssh in background worked fine).

我发现,使用ssh -t -t治愈的问题。也许这可以帮助你。
(队友发现这个在网络上,我们花了这么多时间,我再也没有回去​​读,暗示此文章。我们的系统上的手册页没有给出暗示,这样的事情是可能的)

I found that using ssh -t -t cured the problem. Maybe this can help you too. (a teammate found this on the web, and we had spent so much time, I never went back to read the article that suggested this. The man page on our system gave no hint that such a thing was possible)

希望这有助于。

这篇关于BASH产卵子shell为SSH并继续程序流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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