Re: pre-connect and smtp ?



Hi,

On 2001.08.20 12:59 christophe barbé wrote:
> How can we initiate port forwarding outside of balsa.
> In my experience, I initiate a port forwarding as a side effect of a
> remote
> command which is generally 'sleep 5'. The port forwarding will be
> available
> only 5 seconds but if you connect to this port during this 5 seconds, then
> SSH will close the connection as soon as nobody use it.

Provided the machine you're running ssh on is a desktop that does not allow
outside logins, you would be safe doing it this way:

~/bin/runbalsa
---8<----------8<----------8<----------8<----------8<----------8<-------

#!/bin/bash

(while [ 1 ] ; do ssh -N -L4444:mailserver.domain.com:25
relayserver.domain.com ; done) &

balsa

PID=`ps -ef | grep "4444:" | grep -v grep | awk '{print $2}'`

if [ ! -z "$PID" ] ; then
	kill $PID
fi

---8<----------8<----------8<----------8<----------8<----------8<-------

ssh with the -N option will start up for port forwarding only. It will
accept one connection, then live until the port is closed. The
loop-in-a-subshell will restart it after each use.

Finally, the kill on exit will take care of both the running ssh process and
the shell that started it.

Melanie




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]