Add Comment

You are not currently logged in. If you do not have a user account then please consider creating one and logging in before you post your comment. This will allow you to track replies to your comment, and take part in the site much more freely.

To add your comment, fill in all the boxes below and then preview it to make sure you're happy with the way that it looks.

This is the comment you were replying to, attached to the article Sysvconfig: How not to go postal over a service :


psp for any UNIX system, my own "service" script
Posted by khopesh (129.10.xx.xx) on Thu 21 Feb 2008 at 21:27

I've had a similar script for a long while. It works on older UNIX systems that lack pgrep and bash, and it figures out which type of "ps" program is installed. However, it will not hide the grep line if you are using a regex that ends in a special character:

(from a file sourced by .profile)

[ `uname -s` = SunOS ] && [ -x /usr/ucb/ps ] && alias ps=/usr/ucb/ps
if ps auxww >/dev/null 2>&1 # works in linux + bsd (and solaris w/ ucb's ps)
  then alias psax='ps auxww'
  else alias psax='ps -ef'
fi
psl() {
  local grep=grep start end
  type egrep >/dev/null 2>&1 && grep=egrep
  psax |head -n1 |GREP_COLOR="1;38" $grep .   # bold header
  if [ $# = 0 ]
    then psax
    else
      start="${*%[!]?*+.)$]}" # cut off last character if its not special
      end="${*#$start}"       # get just that last character (if !special)
      psax |$grep -i "$start${end:+[$end]}"   # search for args if present
  fi
}

For my /usr/local/bin/service script, I use the following. Note that the return value isn't screwed up by my error message hack. If you don't trust those last two lines, use   "$RC" "$@"   instead.

#!/bin/sh

RC="/etc/init.d/$1"

case $1 in   # if we're approximating redhat, httpd == apache(2)
  http*|apache*) [ ! -x "$RC" ] && RC="/etc/init.d/apache2" ;;
esac

if [ ! -x "$RC" ]; then
  if [ "$1" = "-list" ] || [ "$1" = "--list" ]; then
    cd /etc/init.d
    find * -type f -perm -u+x \
      |egrep -v '^(skeleton|.*\.dpkg|rc|single|reboot|halt|bootclean)' \
      |xargs ls
    exit 0
  fi

  echo "Invalid service: '$1'" >&2
  echo "You can get a list of services with '`basename $0` --list'" >&2
  echo "Get further help with '`basename $0` SERVICE help'" >&2
  exit 1
fi

shift

# here's a clever hack where we safely change the "Usage: ..." statement
exec 3>&1
exit `(("$RC" "$@" 4>&-; echo $? >&4)|sed 's:/etc/init.d/:service :' 1>&3) 4>&1`

Username:Anonymous
Title:
Your Comment:

Posting Format:

 

Inappropriate comments will be removed.

Some help on entry formatting is available

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search