This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Listing services


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]