#!/bin/bash n1="$0" n2="${n1##*-}" name=${n2%.*} case $name in 'set') command="$1" srv="$2" case ${command} in 'yes'|'start'|'on'|'enable') command='enable' chk='on' svc='start' ;; 'no'|'stop'|'off'|'disable') command='disable' chk='off' svc='stop' ;; *) srv='' ;; esac if [[ "X" == "X${srv}" ]] then echo "Usage: ${0} {enable|disable} {service}" exit 1 fi ;; 'yes'|'start'|'on'|'enable') command='enable' srv="$1" if [[ "X" == "X${srv}" ]] then echo "Usage: ${0} {service}" exit 1 fi chk='on' svc='start' ;; 'no'|'stop'|'off'|'disable') command='disable' srv="$1" if [[ "X" == "X${srv}" ]] then echo "Usage: ${0} {service}" exit 1 fi chk='off' svc='stop' ;; *) echo "Usage: ${0} {enable|disable} {service}" exit 1 ;; esac # echo -e "name=[$name]\ncommand=[${command}]\nservice=[${srv}]" chkconfig ${srv} ${chk} if [ 0 -ne $? ] then echo "${srv} does not seem to be a valid service!" exit 2 fi service ${srv} ${svc} echo "${srv} ${command}d"