Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Dec 2002 15:05:31 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Nelis Lamprecht <nelis@brabys.co.za>
Cc:        questions@freebsd.org
Subject:   Re: Broken Startup Script
Message-ID:  <20021216130531.GE12261@gothmog.gr>
In-Reply-To: <1040035528.444.5.camel@enigma.8ball.co.za>
References:  <1040035528.444.5.camel@enigma.8ball.co.za>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-12-16 12:45, Nelis Lamprecht <nelis@brabys.co.za> wrote:
>
> Since upgrading to latest stable a few of my startup scripts have
> stopped working due to the changes in sh. I have fixed most but not
> sure how to fix the below script which keeps giving me [:
> /usr/local/sbin/snmpd: unexpected operator

> #!/bin/sh
>
> if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
>     echo "$0: Cannot determine the PREFIX" >&2
>     exit 1
> fi
>
> case "$1" in
> start)
> 	[ -x ${PREFIX}/sbin/snmpd -c ${PREFIX}/share/snmp/snmpd.conf ] &&
> ${PREFIX}/sbin/snmpd && echo -n ' snmpd'
> 	;;

If you were trying to combine two tests in one, this is the wrong way
of doing it.  You should at least change it to:

    [ -x ${PREFIX}/sbin/snmpd ] && [ -c ${PREFIX}/share/snmp/snmpd.conf ] && \
    ${PREFIX}/sbin/snmpd && echo -n ' snmpd'

But even then, the test of the second [...] block is completely bogus,
since -c checks whether its operand is a 'character special device'.
I'm positively sure that's not what you meant to test.

If, on the other hand, you are trying to fire up snmpd with a -c
option that points to the proper configuration file that snmpd will
read, you should write this a bit differently:

    [ -x ${PREFIX}/sbin/snmpd ] && \
    ${PREFIX}/sbin/snmpd -c ${PREFIX}/share/snmp/snmpd.conf && \
    echo -n ' snmpd'

That should work better.  You could even make things a little more
verbose, to avoid making mistakes in the future, and write this using
an ``if'' block and quoting the places where $PREFIX is used:

    if [ -x "${PREFIX}/sbin/snmpd" ]; then
	"${PREFIX}/sbin/snmpd" -c "${PREFIX}/share/snmp/snmpd.conf" && \
	echo -n ' snmpd'
    fi

- Giorgos

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021216130531.GE12261>