script to turn off services
Dag Wieers
dag at wieers.com
Wed Aug 16 18:54:29 UTC 2006
On Wed, 16 Aug 2006, Bill Tangren wrote:
> I am trying to write a script that will turn off unneeded services, but I am
> not having any luck. I have tried the following:
>
> service bluetooth status > /dev/null 2>&1
> EXITVALUE=$?
> if [ $EXITVALUE == 0 ]; then
> service bluetooth stop
> chkconfig --level 345 bluetooth off
> fi
>
>
> This works if bluetooth is not installed, but not if it IS installed and
> already turned off. In that case, the service command returns zero and the if
> block is executed.
>
> Does anyone know how to modify this script so that it will run (or tell me
> where I can learn how to modify it)?
The problem is in the bluetooth sysv script. As you probably have noticed,
for most services this is no problem:
[root at server1 root]# service gpm status
gpm is stopped
[root at server1 root]# echo $?
3
[root at server1 root]# service ntpd status
ntpd (pid 12400) is running...
[root at server1 root]# echo $?
0
[root at server1 root]# service bluetooth status
bluetooth: unrecognized service
[root at server1 root]# echo $?
1
But
[root at server1 root]# service bluetooth status
hcid is stopped
sdpd is stopped
hidd is stopped
[root at server1 root]# echo $?
0
If you look inside the script, you can see that the return code is not
being captured. Which one should it capture and exit with ?
For other services, where there's only one process to check, it's quite
simple. Here the solution could be to return 0 if all services are
running. (ie. take the sum of the return codes)
If you think this is a defect and you expected something else. Open a
bugreport in bugzilla and then do a support call and point to this
bugzilla entry.
Kind regards,
-- dag wieers, dag at wieers.com, http://dag.wieers.com/ --
[all I want is a warm bed and a kind word and unlimited power]
More information about the redhat-list
mailing list