Simultanous processes in shell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Siebbel
    New Member
    • Mar 2007
    • 13

    Simultanous processes in shell script

    Dear all,

    I am trying to write a shell script that creates a ssh tunnel to a remote server and checks out a module from a CVS repository. The problem is that the tunnel creation blocks the terminal. That means I have to wait for a moment till the tunnel is established and than apply the CVS commands on a different terminal. How can this be done with a shell script such that the process can be automatic? I already tried to put an ampersand after the ssh line, but then the connection is aborted at the time the CVS commands are entered. Thanks in advance.

    Siebbel

    This is what I tried:
    Code:
    ssh -L 2401:localhost:2401 user@somewhere.com &
    sleep 10
    export CVSROOT=:pserver:cvs@localhost:/data/cvs
    cvs update -d module &
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Take a look at this short guide on SSH Tunneling.
    Google SSH Tunneling if you need more help.

    Comment

    • Siebbel
      New Member
      • Mar 2007
      • 13

      #3
      I googled a lot already but al methods offered did not work. I can fork the tunnel to the background for an amount of time using the command sleep, but then the connection is immediately closed:

      Code:
      ssh -fv -L 2401:localhost:2401 cvs@colab.capitaltoolcompany.com sleep 25
      <enter>
      debug1: Authentication succeeded (publickey).
      debug1: Connections to local port 2401 forwarded to remote address localhost:2401
      debug1: Local forwarding listening on 127.0.0.1 port 2401.
      debug1: channel 0: new [port listener]
      debug1: Local forwarding listening on ::1 port 2401.
      debug1: channel 1: new [port listener]
      debug1: channel 2: new [client-session]
      debug1: Entering interactive session.
      [root@neptune html]# debug1: Sending command: sleep 25
      Press Enter to close this session...
      debug1: client_input_channel_req: channel 2 rtype exit-status reply 0
      debug1: channel 2: free: client-session, nchannels 3
      debug1: channel 0: free: port listener, nchannels 2
      debug1: channel 1: free: port listener, nchannels 1
      debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
      debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
      debug1: Exit status 0
      Here I gave only the final part of the output, since the first part is what one expects when the tunnel is set up. After this output, no connection is available anymore, <enter> terurnes to prompt. I've looked at dozens of pages concerning ssh tunneling but no usefull comments till now. Can anybody help me?

      Siebbel

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        It appears your source port and destination port are the same port on the same machine...Is that what you are trying to do?

        Comment

        • Siebbel
          New Member
          • Mar 2007
          • 13

          #5
          This is also something I got from a ssh tutorial. And it works fine from the command line: when I enter
          Code:
          ssh –v –a –L 2401:localhost:2401 user@remoteserver
          an ssh tunnel is opened and through a different terminal I am able to send the commands I want to, or scp or whatever. The problem lies in the fact that I have to do that in a different terminal and a shell script is run from one. Using the -f option from the command line doesn't work (see output above), although this is how it is described in the literature.

          Siebbel

          Comment

          Working...