May 06, 2008 Archives

06-05-2008 17:13

Services command like Red Hat

I liked using the service command in my Red Hat days, have always missed it on my Debian systems. Thought it would be possible to add it myself but never did look into it. well here it is also with an auto completion ability for the service name.

Create a script /usr/sbin/service


set -e

/etc/init.d/$1 $2 $3
And make it executable
chmod 755 /usr/sbin/service

Then to add auto completion to this, create: /etc/bash_completion.d/service with this inside

# a function for the autocompletion of the service command.

  # set some local variables
  local cur prev


  #if only one completion or a option is being requested
  #then complete against various options
  if [ $COMP_CWORD -eq 1 ]; then
    COMPREPLY=( $( compgen -W "$(ls /etc/init.d)" $cur ))
  elif [ $COMP_CWORD -eq 2 ]; then
    COMPREPLY=( $( compgen -W "start stop restart pause zap status ineed iuse needsme usesme broken" $cur ))
    COMPREPLY=( $( compgen -f $cur ))

  return 0

#setup the completion
complete -F _service_fn service

PS I have created a script to automate this process. Its located here:

Posted by DaveQB | Permanent Link | Categories: IT