简体   繁体   English

使用Windows bat文件和运行脚本文件打开Cygwin

[英]Opening Cygwin with Windows bat file and running script file

I require a tunnel between my windows machine to a UNIX server and wish to automate the process so that on startup the tunnel will be generated for me. 我需要在Windows计算机和UNIX服务器之间建立隧道,并希望自动执行该过程,以便在启动时为我生成隧道。

I installed Cygwin with ssh and autossh to connect to the remote server, built up the connection manually, and have confirmed that the connection works. 我用ssh和autossh安装了Cygwin以连接到远程服务器,手动建立了连接,并确认该连接有效。 The process involves 3 commands, which isn't a lot but something that would be great to have automated. 该过程涉及3个命令,虽然数量不多,但要实现自动化将是一件很棒的事情。

After creating a .sh script file, which includes my autossh connection commands, and saving it using Notepad ++ as a UNIX document (to avoid any potential conflicts regarding the file ending), I can navigate to this script in Cygwin and call bash script.sh . 创建包括我的autossh连接命令的.sh脚本文件,并使用Notepad ++将其保存为UNIX文档(以避免与文件结尾有关的任何潜在冲突)之后,我可以在Cygwin中导航至该脚本并调用bash脚本.sh After which the connection is made and I can work on my server. 建立连接之后,我就可以在服务器上工作了。

My problem comes when creating my bat file: 创建蝙蝠文件时出现问题:

start /d "C:\cygwin\bin\" mintty.exe "C:\Users\user\Documents\Dev\" script.sh

The first part up to and including the .exe file works to open the Cygwin window, but I have been unsuccessful in feeding the script into it. 直至并包括.exe文件的第一部分,都可以打开Cygwin窗口,但是我无法将脚本输入到其中。 I even tried including a --bash command before referencing the script file as follows, but I received an error that the command is unknown: 我什至尝试在引用脚本文件之前包括--bash命令,如下所示,但是我收到一条错误消息,该命令未知:

start /d "C:\cygwin\bin\" mintty.exe --bash "C:\Users\andrew\Documents\Development\" tunnel.sh

Does anyone know if and how it is possible to open a Cygwin window and call a script file within this window? 有谁知道是否以及如何打开Cygwin窗口并在此窗口中调用脚本文件? This is my first time creating a bat file, so I hope this is perhaps a newbie problem that no one even bothers to post a solution online for... 这是我第一次创建bat文件,因此我希望这可能是一个新手问题,甚至没人愿意为在线发布解决方案...

you don't need start. 您不需要开始。 assuming your Cygwin is in C:\\cygwin you need just: 假设您的Cygwin在C:\\cygwin需要:

chdir c:\cygwin\bin
mintty /usr/bin/bash -l -c /cygdrive/c/Users/user/Documents/Dev/script.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM