shell regex matching help
Giles Orr
gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Tue Dec 12 21:22:31 UTC 2006
On 12/12/06, Neil Watson <tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org> wrote:
> I need help with this script.
>
> #!/bin/bash
>
> HOSTNAME=`hostname`
> SERVICE="db2"
> CLUSTAT=`/usr/sbin/clustat -s ${SERVICE}|tail -n1`
> # Should return:
> #db2 your-hostname started
>
> echo $HOSTNAME
> echo $SERVICE
> echo $CLUSTAT
>
> if [[ ${CLUSTAT} = ${SERVICE}[:blank:]+${HOSTNAME}[:blank:]+started ]] ; then
I'm not as good at BASH programming as I ought to be, so my preferred
solution is dictated by limited knowledge ....
I don't understand the above "if ..." line. Wouldn't it be easier to
use ${CLUSTAT##* } and see if that matches "started" rather than
trying to reassemble the correct output? If you need to check
$SERVICE or $HOSTNAME because you're checking several services or
hosts, perhaps check them separately too with similar name mangling?
> echo "Node is active"
> exit 0;
> fi
>
> # Else node is not active.
> echo "Node is not active"
> exit 255
>
> Output:
> :!./activenode
> tor-lx-hadrian
> db2
> db2 tor-lx-hadrian started
> Node is not active
>
> Why is the match failing?
--
Giles
http://www.gilesorr.com/
gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list