[monit 5.25.1] Question on quote escaping

Vladimir Scherbinin <[email protected]>
Newsgroups gmane.comp.monitoring.monit.general
Message-ID <CAKT08Hxtx+S_t2AeHepqU7D-TDOxAEVDUG9VJq+yj1kO-2qTFQ@mail.gmail.com>
Hi,

I have the following check to monitor if all ntp servers configured are
alive

*check program ntpq*
*  with path /bin/bash -c '/usr/bin/ntpq -4pn |tail -n +3 |awk '"'"'{ print
$3 }'"'"' |grep -q 16'*
*  if status = 0 then alert*

I'm using a shell quote escaping extensively to have ' and " in parallel.

Short explanation of multiple single and double quotes:
with path /bin/bash -c '/usr/bin/ntpq -4pn |tail -n +3 |awk '"'"'{ print $3
}'"'"' |grep -q 16'
                                                            ^^^^^
 ^^^^^
                                                            01234
 56789
0. ' - end   first  quotation which uses single quotes
1. " - start second quotation using double quotes
2. ' - quoted character itself
3. " - end   second quotation using double quotes
4. ' - start third  quotation using single quotes
5. ' - end   third  quotation using single quotes
6. " - start fourth quotation using double quotes
7. ' - quoted character itself
8. " - end   fourth quotation using double quotes
9. ' - start fifth  quotation using single quotes
In fact, shell interprets all above as long concatenated string.

When I run this command in shell all is fine and works as expected - no
output and status code is 1.

When the same check is run by monit, I have the following output:
*# monit status ntpq*
*Monit 5.25.1 uptime: 39d 23h 12m*

*Program 'ntpq'*
*  status                       OK*
*  monitoring status            Monitored*
*  monitoring mode              active*
*  on reboot                    start*
*  last exit value              1*
*  last output                  Usage: awk [POSIX or GNU style options] -f
progfile [--] file ...*
*                               Usage: awk [POSIX or GNU style options]
[--] 'program' file ...*
*                               POSIX options: GNU long options: (standard)*
*                                -f progfile --file=progfile*
*                                -F fs --field-separator=fs*
*                                -v var=val --assign=var=val*
*                               Short options: GNU long options:
(extensions)*
*                                -b --characters-as-bytes*
*                                -c --traditional*
*                                -C --copyright*
*                                -d[file] --dump-variables[=file]*
*                                -D[file] --debug[=file]*
*                                -e 'program-text' --source='program-text'*
*                                -E file --exec=file*
*                                -g --gen-pot*
*                                -h --help*
*                                -i includefile --include=includefile*
*                                -l library --load=library*
*                                -L[fatal|invalid] --lint[=fatal|invalid]*
*                                -M --bignum*
*                                -N --use-lc-numeric*
*                                -n --non-decimal-data*
*                                -o[file] --pretty-print[=file]*
*                                -O --optimize*
*                                -p[file]*
*  data collected               Mon, 05 Feb 2018 17:05:56*


I've also tried to quote all expression with double quotes which makes it
even less readable :) with the same result.

Any suggestions on what went wrong would be highly appreciated.
Thanks in advance.

-- 
Vladimir "vovin" Scherbinin.

-- 
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.