<div dir="ltr">On 17 April 2013 01:29, SebA <span dir="ltr"><<a href="mailto:spah@syntec.co.uk" target="_blank">spah@syntec.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Using Jeremy's amazing example here<br>
<a href="http://lists.xymon.com/pipermail/xymon/2013-January/036615.html" target="_blank">http://lists.xymon.com/pipermail/xymon/2013-January/036615.html</a> I'm trying<br>
to do something a little simpler...<br></blockquote><div><br></div><div style>Yeah, simpler is good.  I wouldn't call my example "amazing", instead it's "complicated", or even "hackgly".  Actually, I'm amazed it works!</div>

<div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">log:`exec 2>/dev/null; F=/path/to/file/log.log; T=/tmp/substitutedlog.log;<br>


C=$(sed 's/debug:.*/DEBUG LINE DETECTED AND REPLACED/' $F > $T); echo<br>
$T`:1024<br></blockquote><div><br></div><div style>Yup.</div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

But /usr/share/xymon-client/logs/xymonclient.log gets this:<br>
<br>
sh: -c: line 0: unexpected EOF while looking for matching `''<br>
sh: -c: line 1: syntax error: unexpected end of file<br></blockquote><div><br></div><div style>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.</div>

<div style><br></div><div style>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.</div>

<div style><br></div><div style>So this might stop the errors, and let the full command parse correctly:</div><div style><br></div><div style>log:`exec 2>/dev/null; COLON=<span style="color:rgb(0,0,0);white-space:pre-wrap">$(printf "\x3a");</span> 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</div>

<div style><br></div><div style>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:</div>

<div style><br></div><div style><div>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</div><div><br>

</div><div style>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.</div>

<div style><br></div></div><div style>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:</div>

<div style><br></div><div style><div>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</div><div><br></div>

<div style>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:</div><div style><br></div><div style><div>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</div>

<div><br></div></div></div><div style><div style>J</div><div style><br></div></div></div></div></div>