Note that there are some explanatory texts on larger screens.

plurals
  1. POSpawn subshell for SSH and continue with program flow
    primarykey
    data
    text
    <p>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 <code>iwconfig</code>.</p> <p>This is what I want it to do:</p> <pre><code>cat file1 &gt; 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 &amp; # 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 &amp; # I want myProg2 running in the background until I shutdown my computer. start tweetdeck, thunderbird close the terminal with the "exit" command </code></pre> <p>The problem is that campusB's wireless network is behind a firewall, which grants me internet access ONLY after I successfully ssh by <code>username@domain</code>. 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).</p> <p>When I try doing just <code>ssh username@domain</code>, the script stops because I don't exit the <code>ssh</code> command. I can't <code>^C</code> 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 <code>ssh</code> session.</p> <p>Some googling brought me to <a href="http://tldp.org/LDP/abs/html/subshells.html" rel="nofollow"><code>subshell</code></a>, 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 <code>ssh</code> password in the script</p> <p>Further, ampersanding the <code>ssh</code> call (<code>ssh username@domain &amp;</code>) doesn't seem to do any good (can anyone explain why?)</p> <p>Thank you in advance</p> <p><strong>EDIT</strong></p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload