Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor Windows services with Cygwin

Tags:

cygwin

I'm trying to move some of my routine shell operations from PowerShell to Cygwin, mostly as an educational exercise, but also because I'm really beginning to love some of the Linux flavor tools. I'm still trying work out how to list/manipulate Windows services. PowerShell had some very handy tools for this, such as:

stop-service [pattern]
start-service [pattern]
gsv (or get-service) [pattern]

I work with a lot of custom services lately and would love to not have to switch over to PowerShell to do this in my regular workflow. Has anybody worked this out? Several attempts to google this have been stymied by lots of stuff on how to deal with Cygwin running as a service.

like image 949
brettman Avatar asked Apr 25 '12 13:04

brettman


People also ask

How do I monitor Windows services?

Go to Services and Processes tab. Click on Discover Services and Processes . This will discover the processes & services running in your Windows server. Select the service you wish to monitor and click Add Service and Process .

Is Cygwin like Linux?

Cygwin is a collection of open source tools that allows Unix or Linux applications to be compiled and run on a Microsoft Windows operating system (OS) from within a Linux-like interface. Cygwin offers users a Linux-like experience in a Windows environment.

What can I do with Cygwin?

Cygwin applications are native Windows applications. So they can easily access the same files and directories as any other Windows application. Cygwin allow you to run the binaries natively without the overhead of Linux VM. You can run Gnome terminal and xterm with Cygwin.


1 Answers

Invoke PowerShell commands from within Cygwin:

cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command "gsv"

And a more general solution would be to create a script powershell.sh which contains:

#!/bin/bash
set -e
set -u
cmd /c '%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe' -Command "$@"

After which you can run: ./powershell.sh gsv or whatever commands you need.

like image 133
sinelaw Avatar answered Oct 09 '22 22:10

sinelaw