delorie.com/archives/browse.cgi | search |
X-Spam-Check-By: | sourceware.org |
Message-ID: | <46B0178A.5887EC7F@dessent.net> |
Date: | Tue, 31 Jul 2007 22:18:02 -0700 |
From: | Brian Dessent <brian AT dessent DOT net> |
X-Mailer: | Mozilla 4.79 [en] (Windows NT 5.0; U) |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: How to close a SSH connection from a BAT file |
References: | <loom DOT 20070801T062742-243 AT post DOT gmane DOT org> |
X-IsSubscribed: | yes |
Reply-To: | cygwin AT cygwin DOT com |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Anthony de Sousa wrote: > I am hoping that someone may be able to advise as to whether the following is > possible. I have a server running SSH as a service (SRVA) and another server > (SRVB) which runs the SSH client and port forwards port 139. On SRVB I have > an existing BAT file that I wish to wrap the port forwarding around so that > port 139 goes through port 22. This all works except that I also wand to drop > the SSH connection after the BAT file has finished what it needs to do. Is > this possible as I am finding that I end up with two command windows with one > still running the SSH connection. The simple BAT that I initiate is as follows: > > @echo off > cd c:\dirb > rem the following line starts the existing bat file in a seperate window > Start run1.bat > rem > cd c:\cygwin\bin > bash -c "(ssh -N -L 10.0.0.1:139:20.250.205.96:139 srvusr AT srvb)" > > As stated this all works and the output of run1.bat is transferred to SRVB > however I would like the connection dropped and the window terminated. The best way is to run the ssh command as a service using cygrunsrv. Then your batch file amounts to: @echo off net start sshtunnelservicename run1.bat net stop sshtunnelservicename Failing that you can record the PID and use it to kill the ssh process later: @echo off setsid sh -c 'echo $$ >/var/run/ssh.pid; exec ssh -N -L 10.0.0.1:139:20.250.205.96:139 srvusr AT srvb' run1.bat sh -c 'kill -INT $(cat /var/run/ssh.pid)' (This assumes you have the Cygwin bin directory in the PATH, if you don't then just use absolute paths to setsid and bash.) Also, if you only want the one command window I don't see why you are doing "start run1.bat". You don't need to use start, just call run1.bat from the other batch file and when it's done stop the ssh process. Brian -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |