delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
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 |
Message-ID: | <4228D319.24DBAF6D@dessent.net> |
Date: | Fri, 04 Mar 2005 13:28:57 -0800 |
From: | Brian Dessent <brian AT dessent DOT net> |
Organization: | My own little world... |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: Listing services |
References: | <200503041150 DOT 14903 DOT colin AT breame DOT net> <42289B1B DOT 7000103 AT acm DOT org> |
X-IsSubscribed: | yes |
Reply-To: | cygwin AT cygwin DOT com |
David Rothenberger wrote: > I do it with the following script which uses /proc. That's an interesting script but it has a couple of deficiencies. It does not list services with names that start with a "." and it breaks on services with a space in the name when -n is used. It's also very slow with -n, as there's no need to invoke awk once for each service, and using forking /bin/cat to read each description is costly. Here's a slightly tweaked version that fixes the above problems and runs about 30 times faster. (0m13.722s down to 0m0.489s on my system at least.) #!/bin/sh usage() { cat <<EOF usage: `basename $0` [-n] [--] -n: Display names EOF } displayNames() { false; } while getopts :n OPT; do case $OPT in n|+n) displayNames() { true; } ;; *) usage exit 2 esac done shift `expr $OPTIND - 1` srvKey=/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services if displayNames; then find $srvKey/ -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | \ sort -f | \ ( while read s; do descr="" [ -f "$srvKey/$s/DisplayName" ] && \ read descr <$srvKey/$s/DisplayName; echo -e "$s\t$descr" done ) | \ awk -F \\t '{printf("%-30s: %s\n", $1, $2)}' else find $srvKey/ -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | \ sort -f fi --- 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 |