scripted ssh login

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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,


Re: scripted ssh login

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

Quoted text here. Click to load it

    Can't you use scp?

Re: scripted ssh login

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

Quoted text here. Click to load it

Use exit, it's just a regular terminal session.
Ren=E9 Berber

Re: scripted ssh login

Quoted text here. Click to load it

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
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.

Site Timeline