scripted ssh login - SSH

This is a discussion on scripted ssh login - SSH ; Hi all, I need to fetch some data from a Database which can be reached via a ssh-tunneled TCP-port. Manually, everything works fine. First, the ssh-connection is established and after that, the data is fetched. Now I need to run ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: scripted ssh login

  1. scripted ssh login


    Hi all,

    I need to fetch some data from a Database which can be reached via a ssh-tunneled TCP-port.
    Manually, everything works fine. First, the ssh-connection is established and after that, the
    data is fetched.

    Now I need to run this as a cron job, so I need to establish the ssh-connection by script.
    That should work without problems because the login is without password. But how can I shut
    down the connection after the data is transfered?

    Any ideas?

    Thanks a lot,

    Florian

  2. Re: scripted ssh login

    On Sat, 28 Jul 2007 17:54:15 +0200, Florian Schoenbeck wrote:

    > Hi all,
    >
    > I need to fetch some data from a Database which can be reached via a
    > ssh-tunneled TCP-port. Manually, everything works fine. First, the
    > ssh-connection is established and after that, the data is fetched.
    >
    > Now I need to run this as a cron job, so I need to establish the
    > ssh-connection by script. That should work without problems because the
    > login is without password. But how can I shut down the connection after
    > the data is transfered?
    >
    > Any ideas?
    >


    Can't you use scp?

  3. Re: scripted ssh login

    On Jul 28, 10:54 am, Florian Schoenbeck wrote:

    > I need to fetch some data from a Database which can be reached via a ssh-tunneled TCP-port.
    > Manually, everything works fine. First, the ssh-connection is establishedand after that, the
    > data is fetched.
    >
    > Now I need to run this as a cron job, so I need to establish the ssh-connection by script.
    > That should work without problems because the login is without password. But how can I shut
    > down the connection after the data is transfered?
    >
    > Any ideas?


    Use exit, it's just a regular terminal session.
    --
    René Berber


  4. Re: scripted ssh login

    On 2007-07-28, Florian Schoenbeck wrote:
    > I need to fetch some data from a Database which can be reached via
    > a ssh-tunneled TCP-port. Manually, everything works fine. First,
    > the ssh-connection is established and after that, the data is fetched.
    >
    > Now I need to run this as a cron job, so I need to establish the
    > ssh-connection by script. That should work without problems because
    > the login is without password. But how can I shut down the connection
    > after the data is transfered?


    What I used to do was run something like "sleep 5" with ssh -f and the
    tunnel. If the sleep exits before the tunnel closes, the remote sshd
    will wait for the tunnel to close before closing the ssh connection, so
    the sleep just needs to be long enough to establish the tunneled
    connection. This should work for most software and versions.

    Another alternative, if you're using a recent OpenSSH, is to use the
    ControlMaster option when establishing the connection, then use "ssh -O
    exit" option to shut the master down when your script is done.

    --
    Darren Tucker (dtucker at zip.com.au)
    GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
    usually comes from bad judgement.

+ Reply to Thread