On Wed, Feb 09, 2011 at 05:00:31PM +0100, Dejan Muhamedagic wrote:
> On Wed, Feb 09, 2011 at 03:41:26PM +0100, Lars Ellenberg wrote:
> > On Wed, Feb 09, 2011 at 02:03:04PM +0100, Dejan Muhamedagic wrote:
> > > >     hadr_vars=$(echo "$output" |\
> > > >         awk '$0 ~/HADR database role/ {printf "HADR_ROLE=%s; ", $NF;}
> > > >         $0 ~/HADR_TIMEOUT/ {printf "HADR_TIMEOUT=%s; ", $NF;}
> > > >         $0 ~/First active log file/ {printf "FIRST_ACTIVE_LOG=%s\n", 
> > > > $NF;}
> > > >         $0 ~/HADR_PEER_WINDOW/ {printf "HADR_PEER_WINDOW=%s\n", $NF;}')
> > > 
> > > You can leave out "$0 ~". It is going to work this way too,
> > > but otherwise it does not look very awk :)
> > > Also, since it goes to eval below, better add single quotes around
> > > /HADR_PEER_WINDOW/ {printf "HADR_PEER_WINDOW='%s'\n" ...
> > > 
> > > >     # sets HADR_ROLE HADR_TIMEOUT HADR_PEER_WINDOW 
> > > >     eval $hadr_vars
> > 
> > Hmm. Since both shell and awk by default do word split on white space,
> > how about this, without doing eval:
> > set -- $(echo "$output" |
> >     awk '/HADR database role/       { role=$NF; }
> >          /HADR_TIMEOUT/             { timeout=$NF; }
> >          /First active log file/    { log=$NF; }
> >          /HADR_PEER_WINDOW/         { window=$NF; }
> >          END { printf ".%s\t.%s\t.%s\t.%s\n",
> >             role, timeout, log, window; }')
> >     HADR_ROLE=${1#.}
> >     HADR_TIMEOUT=${2#.}
> >     FIRST_ACTIVE_LOG=${3#.}
> >     HADR_PEER_WINDOW=${4#.}
> 
> Isn't this a bashism?

No.
Which part of it seems suspicious to you?

> Which is absolutely understandable. But note that this input
> comes from the db2 program, so it shouldn't be totally
> unexpected.

As long as you can be sure there never will be single quotes part of the
value, you can try with your suggestiong of '%s'.  Otherwise, you'd need
to first quote any and all singlequotes.

I like mine better, still ;-)

-- 
: Lars Ellenberg
: LINBIT | Your Way to High Availability
: DRBD/HA support and consulting http://www.linbit.com

DRBD® and LINBIT® are registered trademarks of LINBIT, Austria.
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to