On Wed, Oct 06, 2010 at 06:51:05AM -0600, Serge Dubrouski wrote: > On Wed, Oct 6, 2010 at 5:51 AM, Lars Ellenberg > <lars.ellenb...@linbit.com> wrote: > > On Wed, Oct 06, 2010 at 01:31:07PM +0900, renayama19661...@ybb.ne.jp wrote: > >> Hi Serge, > >> > >> I confirm the movement of your patch from now on. > >> And I am going to contribute the patch of the change of loglevel of the > >> monitor processing at the time > >> of the start. > >> > >> However, there is a problem to your this patch. > >> The -q option of the monitor is lost. > >> > >> - runasowner -q "$OCF_RESKEY_psql $psql_options -c 'select now();'" > >> + runasowner "$OCF_RESKEY_psql $psql_options -c > >> '$OCF_RESKEY_monitor_sql'" > > > > Make sure you properly shellescape OCF_RESKEY_monitor_sql first, > > or you'll get unexpected results -- it may contain single qutotes itself. > > Thanks. Attached is the final (I hope) version of this patch.
> - runasowner -q "$OCF_RESKEY_psql $psql_options -c 'select now();'" > + runasowner -q "$OCF_RESKEY_psql $psql_options -c > \"$OCF_RESKEY_monitor_sql\"" Nice try ;-) It may contain double quotes just the same. my_runasowner() { # actually is is su $someuser -c "$*", but # for demo it's equivalent to: bash -c "$*"; } x="blub" my_runasowner "echo blah $x" blah blub expected. x="; echo blub" my_runasowner "echo blah $x" blah blub oh. let's quote it. x="; echo blub" my_runasowner "echo blah \"$x\"" blah ; echo blub yes, we fixed it. Or, did we? x="\"; echo blub\"" my_runasowner "echo blah \"$x\"" blah blub Oh ;( You have to _shell escape_ that variable. Not add quotes around it in a string that will be passed as input to a subshell. In sufficiently recent bash, you could do printf -v escaped %q "$unescaped", and be done with it. In stupid sh, you may have to do something similar to escaped=$(echo "$unescaped" | sed -e "s/'/'\\\\''/g"): x="'; echo \\ \$(uname -a); echo blub'" x=$(echo "$x" | sed -e "s/'/'\\\\''/g") my_runasowner "echo blah '$x'" blah '; echo \ $(uname -a); echo blub' Seems like we're good, after all. end-of-shell-quoting-workshop -- : 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/