OT: BASH script to Windows .bat file conversion

Erik Bixby erik.bixby at gmail.com
Mon Nov 6 18:44:14 MST 2006


[This line intentionally left blank.]
I have a script that does a job for me in the Linux world.  The script follows:

#!/bin/bash
# Script to see if SSH tunnel is up, and bring it up if it's down

if test `netstat -an | grep LISTEN | grep :59999 | wc -l` -lt 1
then
ssh -N -T -R 60000:localhost:22 -L 59999:localhost:3128
tunneler at host1.example.com -g
fi

I run this script in a cron job, and it does a respectable job of
keeping a SSH tunnel up between two Linux hosts (although,
constructive input is always welcome).  I am looking to do something
similar with a Windows host.  I have a plink.exe command line that
establishes a connection and forwards my ports all around.  However, I
am hoping someone might be able to help me with an elegant method of
checking for a link already up, and only running plink.exe if
necessary.  I would prefer to not check for plink.exe running, in case
I decide to set up multiple instances.  I'm hoping someone might be
able to help me with a batch file that accomplishes the same goal as
this shell script that I can run periodically on the Windows hosts.

And, for the curious, I'm trying to set this up, amongst other
reasons, so my in-laws' computers will establish a connection to a
machine I can connect to as well, for remote administration.

As always, I thank everyone in advance for your time in considering my quandary.
-Erik Bixby


More information about the PLUG-discuss mailing list