[Xymon] client-local.cfg backticks expression help

Jeremy Laidman jlaidman at rebel-it.com.au
Wed Apr 17 03:02:00 CEST 2013


On 17 April 2013 01:29, SebA <spah at syntec.co.uk> wrote:

> Using Jeremy's amazing example here
> http://lists.xymon.com/pipermail/xymon/2013-January/036615.html I'm trying
> to do something a little simpler...
>

Yeah, simpler is good.  I wouldn't call my example "amazing", instead it's
"complicated", or even "hackgly".  Actually, I'm amazed it works!

log:`exec 2>/dev/null; F=/path/to/file/log.log; T=/tmp/substitutedlog.log;
> C=$(sed 's/debug:.*/DEBUG LINE DETECTED AND REPLACED/' $F > $T); echo
> $T`:1024
>

Yup.

But /usr/share/xymon-client/logs/xymonclient.log gets this:
>
> sh: -c: line 0: unexpected EOF while looking for matching `''
> sh: -c: line 1: syntax error: unexpected end of file
>

I'm fairly sure the problem is the colon in "debug:".  The Xymon
client-side binary logfetch parses the log line from
/tmp/logfetch.$HOSTNAME.cfg.  The first thing it does is to split the line
on the colon delimiter, into three parts, the last one being the max log
message size.  The logfetch program doesn't process any escapes or quoting,
and only cares about the colons.

In my post to which you linked, I mentioned this problem.  I handled it by
putting creating a quote using printf from a hex representation, put it in
a variable ($Z), and used that in my commands.

So this might stop the errors, and let the full command parse correctly:

log:`exec 2>/dev/null; COLON=$(printf "\x3a"); F=/path/to/file/log.log;
T=/tmp/substitutedlog.log;C=$(sed "s/debug${COLON}.*/DEBUG LINE DETECTED
AND REPLACED/" $F > $T); echo $T`:1024

This could be considered an obscure way of quoting, so I could get the
colon into the grep parameter.  Unlike grep, GNU sed can use quoted hex to
represent arbitrary characters, so you might be able to get away with this:

log:`exec 2>/dev/null; F=/path/to/file/log.log;
T=/tmp/substitutedlog.log;C=$(sed "s/debug\x3a.*/DEBUG LINE DETECTED AND
REPLACED/" $F > $T); echo $T`:1024

In bash, the same \xnn format is expanded in strings of the form $'...', so
this can be used if you weren't using sed to do pattern matching.  For
example: grep $'debug\x3a.*' > /tmp/tmpfile.

I'm not sure why you're using C=$() rather than just the commands -
probably just a hang-over from my example.  There's unlikely to be any
output to put into $C, and you don't use it anyway.  I had it in my post
because I wanted to do some calculations with it.  So you can simplify this
to be:

log:`exec 2>/dev/null; F=/path/to/file/log.log;
T=/tmp/substitutedlog.log;sed "s/debug\x2a.*/DEBUG LINE DETECTED AND
REPLACED/" $F > $T; echo $T`:1024

In fact, this is almost simple enough that variables don't aid
maintainability, so I'd probably go with this, which is easier for a
sysadmin to grok IMHO:

log:`sed "s/debug\x2a.*/DEBUG LINE DETECTED AND REPLACED/"
/path/to/file/log.log > /tmp/substitutedlog.log 2>/dev/null; echo
/tmp/substitutedlog.log`:1024

J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20130417/127161c5/attachment.html>


More information about the Xymon mailing list