`

在windows里直接运行cygwin脚本

 
阅读更多
cygwin是个很好用的东西,问题是,我们想让系统自动化启动一些东西,
比如在windows启动时,调用cygwin的脚本、启动cygwin里的nginx,启动
windows的MySQL数据库等。

这时就需要通过windows直接运行cygwin里的脚本或命令了

有些哥们确把很多事都想好了。

以下第一种方案经测试可行,可以直接启动nginx,执行脚本。

方案一
D:\cygwin64\bin\run bash --login -c  /home/someuser/shell/runs.sh



Running a shell Script Directly from windows
引用


Running a shell Script Directly from windows

    From: Fred Kulack <kulack at us dot ibm dot com>
    To: cygwin at cygwin dot com
    Date: Thu, 8 Jul 2004 11:14:28 -0500
    Subject: Re: Running a shell Script Directly from windows

I have had the best luck using the 'run' utility to avoid extra
consoles and other 'shtuff' like that.
Haven't seen any doc about it though so it may disappear.
Dunno the details.

For example, I create a shortcut for running X so that I don't
get the extra console window where bash ran...

That shortcut runs this:
C:\cygwin\usr\X11R6\bin\run.exe bash --login -c startx

Clearly your path needs to be setup correctly.


"The stuff we call "software" is not like anything that human society
  is used to thinking about. Software is something like a machine, and
  something like mathematics, and something like language, and
  something like thought, and art, and information...
  but software is not in fact any of those other things."
Bruce Sterling - The Hacker Crackdown

Fred A. Kulack - IBM eServer iSeries - Enterprise Application Solutions
ERP, Java DB2 access, Jdbc, JTA, etc...
IBM in Rochester, MN  (Phone: 507.253.5982   T/L 553-5982)
mailto:kulack/us.ibm.com   Personal: mailto:kulack/magnaspeed.net
AIM Home:FKulack  AIM Work:FKulackWrk
MSN Work: fakulack/hotmail.com (replace email / with @)

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





方案二
Running a shell Script Directly from windows
引用

Re: Running a shell Script Directly from windows

    From: Brian Dessent <brian at dessent dot net>
    To: cygwin at cygwin dot com
    Date: Wed, 07 Jul 2004 19:32:24 -0700
    Subject: Re: Running a shell Script Directly from windows
    Organization: My own little world...
    References: <Pine.LNX.4.44.0407072102550.1460-100000@ccc3.wpi.edu>
    Reply-to: cygwin at cygwin dot com

Scott Emerson Longley wrote:

> I am wondering if Cygwin provides a way to run shell scripts or other
> programs that run within Cygwin, directly from windows (or a .bat). In
> other words, I would like to double-click something on my desktop and have
> it run the shell script. I have fooled a little with bash command-line
> options and whatnot, but to no avail. Any insight or URL's that lead to an
> answer would be greatly appreciated.

Create a shortcut that runs "sh.exe /path/to/script.sh".  When you click
on it your script will run in a command window.  If your cygwin bin
directory is not in your path then the shortcut will have to include it,
i.e. "c:\cygwin\bin\sh.exe /home/foo/bar.sh".  The executable's location
is a Windows path, the args to it are POSIX paths.  If the script has
something other than /bin/sh in the shebang, then substitute
appropriately.

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/





rem window调用cygwin脚本
@echo off

if  "%1" neq "stop" ( goto startSys  ) else ( goto stopSys  )

:startSys
echo 启动系统。。。
D:\cygwin64\bin\run bash --login -c  /home/someone/shell/runs.sh -wait
goto end

:stopSys
echo 停止系统。。。
D:\cygwin64\bin\run bash --login -c  /home/someone/shell/stop.sh -wait
goto end

:end

echo 执行完成。。。



通过cygwin脚本启动和停止MySQL、tomcat、nginx

#!/bin/bash
#/home/someuser/shell/runs.sh

if  [ "$1" != "stop" ];  then
	echo start now . . .
	# start msyql
	echo start mysql  . . .
	/cygdrive/d/mysql-5.6.10-winx64/bin/mysqld &
	
	#start tomcat
	echo start tomcat7  . . .
	net start "tomcat7"
	
	# start nginx
	echo start nginx  . . .
	/usr/local/nginx/sbin/nginx.exe
	
else

	echo stop now . . .
	# stop msyql
	echo stop mysql  . . .
	/cygdrive/d/mysql-5.6.10-winx64/bin/mysqladmin -uroot -proot shutdown &
	
	#stop tomcat
	echo stop tomcat7 . . .
	net stop "tomcat7"
	
	# stop nginx
	echo stop nginx . . .
	/usr/local/nginx/sbin/nginx.exe -s stop


fi

echo done . . . 





Unix/Linux下一般想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行。比如我们要运行mysql在后台:

         /usr/local/mysql/bin/mysqld_safe --user=mysql &

 但是我们很多程序并不象mysqld一样可以做成守护进程,可能我们的程序只是普通程序而已,一般这种程序即使使用 & 结尾,如果终端关闭,那么程序也会被关闭。为了能够后台运行,我们需要使用nohup这个命令,比如我们有个start.sh需要在后台运行,并且希望在后台能够一直运行,那么就使用nohup:

            nohup /root/start.sh &

          在shell中回车后提示:
分享到:
评论

相关推荐

    cygwin 交叉编译的 coturn 服务器可以在windows 下运行

    Cygwin 是一个在Windows上模拟Linux环境的工具集,它允许在Windows系统上运行许多原本为Linux或Unix设计的软件。 本文将详细讲解如何在Cygwin环境下交叉编译coturn服务器,并使其在Windows系统下运行。 1. **...

    在Windows下本地安装Cygwin

    在Windows环境下,Cygwin是一个流行的开源工具,它提供了一个模拟Unix环境的层,使得用户可以在Windows系统上运行许多原本只适用于Linux或Unix的操作。Cygwin的主要目标是使开发者能够在Windows上编译和运行GNU工具...

    windows平台下载安装cygwin

    Cygwin是一个开源软件,它提供了一个类似于Linux的环境,使开发者能够在Windows系统上运行许多原本只能在Unix或Linux环境下执行的命令行工具和应用程序。接下来,我们将详细讨论如何在Windows上下载和安装Cygwin。 ...

    PX4.Windows.Cygwin.Toolchain

    其核心在于提供了一个在Windows平台上运行类Unix应用程序、Shell脚本和命令行工具的解决方案。 首先,Cygwin是这款软件的基础,它是一个开源的免费软件,旨在为用户提供与Unix相似的开发环境。通过Cygwin,Windows...

    windows下安装Cygwin指南含安装包

    在Windows操作系统上,Cygwin是一个非常有用的工具,它提供了一个类UNIX的环境,使得开发者可以在Windows系统上运行许多原本只能在Linux或Unix系统中执行的命令行工具和应用程序。Cygwin通过模拟POSIX接口,使用户...

    redis for Windows 7.0.7 使用cygwin编译

    Cygwin是一个在Windows上模拟Linux环境的开源软件集合,它提供了许多Unix命令行工具和开发工具,使得在Windows下编译和运行像Redis这样的开源项目成为可能。在Windows 7.0.7系统中使用Cygwin编译Redis 7.0.7版本,...

    Windows下快速安装Cygwin

    它通过在Windows上模拟一个POSIX兼容的运行环境,使得用户能够在不改变原有开发环境的前提下,享受到类似于Linux的操作体验。这对于习惯于Linux开发环境而又不得不在Windows系统工作的开发者来说,无疑是一个非常...

    cygwin windows下编译

    在Windows操作系统上,由于其与Linux环境的差异,直接编译和运行Linux代码可能会遇到很多问题。为了在Windows系统中实现Linux开发环境的功能,我们可以利用Cygwin这一工具。Cygwin是一个开源软件集合,它提供了一个...

    Cygwin2.850离线安装包

    Cygwin是一款强大的开源工具,它为Windows操作系统提供了一个类UNIX环境,允许用户在Windows上运行许多GNU/Linux命令行工具和应用程序。Cygwin2.850是该软件的一个特定版本,发布于2014年8月15日。这个离线安装包...

    cdo-1.9.7.1-cygwin64-Win10.zip

    "cygwin64"部分表明这个版本是基于Cygwin环境构建的,Cygwin是一个在Windows上模拟Linux环境的开源工具集,使得CDO这样的Unix/Linux风格的软件可以在Windows系统下运行。 压缩包内的两个核心文件: 1. **cygeccodes...

    Cygwin

    1. **模拟环境**:Cygwin通过在Windows系统上构建一个类似于Linux的运行时环境,使得命令行工具、编译器、shell脚本以及许多其他Linux应用能够正常运行。它提供了POSIX接口,让开发者可以在Windows环境下使用Unix...

    在windows下配置crontab

    【在Windows下配置crontab】的知识点主要集中在如何在Windows环境中使用Cygwin来实现类似于Linux中的计划任务管理。Crontab是Linux和Unix系统中用于管理周期性任务的工具,而在Windows系统中,由于Dos Scripts的功能...

    收集到的cygwin使用资料

    若要在 Windows 下运行 Cygwin 的 Shell 脚本,首先需要将 Cygwin 的 bin 目录添加到 PATH 中。随后,在 `$CYGWIN` 目录的 `/var/` 下创建脚本文件(如 `t.sh`),并确保脚本中的所有路径都使用 Cygwin 的路径风格...

    cygwin直接使用包

    Cygwin的工作原理是通过一个名为“Cygwin DLL”的动态链接库,将Windows API转换为POSIX接口,从而使Linux程序能够在Windows上运行。这意味着开发者无需修改代码,就能将许多开源工具引入到Windows开发环境中。 **...

    java程序产品包模板-内置linux和Windows通用shell启动停止脚本(无需系统安装Java运行环境).zip

    该压缩包文件“java程序产品包模板-内置linux和Windows通用shell启动停止脚本(无需系统安装Java运行环境).zip”提供了一套适用于Java程序的通用打包方案,特别强调了其能够在Linux和Windows操作系统上无缝运行,且不...

    cygwin1.7离线安装包

    安装过程中,Cygwin还会设置环境变量,确保在Windows命令提示符下可以正常运行Cygwin的命令。 总之,Cygwin1.7离线安装包为Windows用户提供了一个在本地模拟Linux环境的解决方案,特别是对于开发者和需要使用Linux...

    Windows + Cygwin + NS-2安装

    Cygwin是一个开源工具集,可以在Windows上提供一个类UNIX的环境,使用户能够运行许多原本只支持Linux或Unix系统的应用程序。 首先,你需要下载Cygwin的安装包,通常以rar格式提供。解压缩后,找到并运行`setup.exe`...

    cygwin64安装包

    Cygwin通过提供一个兼容层,使得这些工具可以在Windows上运行,特别适合于需要在Windows上进行服务器端编程、脚本编写或者命令行操作的用户。用户可以利用Cygwin在Windows系统上开发、测试和运行原本为Linux设计的...

Global site tag (gtag.js) - Google Analytics