<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Jeremy,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The 2nd option works perfectly thanks.  I tried variants of \`, (), export, with no results, but this was so simple.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks again<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Greg Shea<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>EMC Corporation<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Jeremy Laidman [mailto:jlaidman@rebel-it.com.au] <br><b>Sent:</b> Tuesday, May 14, 2013 12:34 AM<br><b>To:</b> shea, greg<br><b>Cc:</b> xymon@xymon.com<br><b>Subject:</b> Re: [Xymon] Logfile syntax client-local.cfg<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>Greg<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>So there are multiple logfiles at any one time?<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Let's say you want the last logfile in that form, regardless of the date:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>log:`find /opt/NetQoS/logs/nqnapacapd_\* -mtime -2 2>/dev/null | tail -1`<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>This gets all files with that name and are up to 2 days old, and gets the last one.  This assumes that "find" shows files in date order, which should be true because of the YYMMDD format you're using.  You might think to do the same with "ls" or "echo" rather than find, but these give an output with the asterisk when there are no files found.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Or, let's say you only want to inspect a file if it has today's date, even if it's not the latest, or ignoring yesterday's file even if it is the latest:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>log:`echo /opt/NetQoS/logs/nqnapacapd_$(date +%Y%m%d)"`<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The problem here is that there's no way to use backquotes, and no simple way to escape them.  So I used bash's ability to use $(cmd) as an equivalent to `cmd`.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>If you don't have bash, this should work:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>log:`printf "/opt/NetQoS/logs/nqnapacapd_"; date +%Y%m%d`<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The printf generates the start of the log filename, but suppresses the newline.  Then the date command output is tacked onto the end of the filename, ready for the logfetch process to use.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>If you don't have printf, then you can do the same newline-suppression with various forms of echo available in different shells, such as "echo -n text" or "echo text\c".  Or to make it shell-agnostic, use the echo binary /usr/bin/echo which typically supports the "\c" newline suppression method.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Or even simpler, use the date command to also show the filename part too:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>log:`date "+/opt/NetQoS/logs/nqnapacapd_%Y%m%d"`<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Bear in mind that your log rotation might not happen at midnight.  If this is the case, you might want to look at yesterday's log for the first hour or two of the day.  The GNU "date" command can be told to use an offset, like so:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>log:`date --date "now -90 minutes" "+/opt/NetQoS/logs/nqnapacapd_%Y%m%d"`<o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>For non-GNU date commands that don't support "--date", you can simulate such an offset by overriding the timezone environment variable with an offset, with granularity of an hour.  So if your timezone is offset from UTC by +7 (7 hours ahead) and you wanted to look at the log for yesterday in the first hour of the day and from today for the rest of the time, you could use this:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>log:`TZ=UTC+6 date "+/opt/NetQoS/logs/nqnapacapd_%Y%m%d"`<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Note that I can't get this to work to give the correct time for me, probably because my understanding of how TZ affects the date command is not very good.  For some reason, I can't get the date command to show my current time even when I set TZ to "XYZ+10" where my timezone is currently 10 hours ahead of UTC, and instead I have to use "TZ=XYZ-10" for it to work for me.  But if you set the string to "+%H:M:S" and play around with the timezone offset, you can work out what it needs to be to get the what the log was N hours ago.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>To cope with log rotation, I'd be using the very first example above, that always shows the log file with the latest timestamp, but being mindful that this can be wrong if a logfile was created during an fault with the system clock (eg someone accidentally set the year to 2014), causing the "latest" logfile to be wrong for 12 months.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>J<o:p></o:p></p></div></div></div><div><p class=MsoNormal><o:p> </o:p></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><p class=MsoNormal>On 14 May 2013 04:17, shea, greg <<a href="mailto:greg.shea@emc.com" target="_blank">greg.shea@emc.com</a>> wrote:<o:p></o:p></p><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Hi folks,<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Need some help with adding this logfile to client-local.cfg.  I have a logfile like " /opt/NetQoS/logs/nqnapacapd_20130513.log"<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>I know I can create that date via `date '+%Y%m%d'`, but I've tried a number of ways to add this, but none were successful.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Any help with the correct syntax would be appreciated.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Greg Shea<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>EMC Corporation<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><br>_______________________________________________<br>Xymon mailing list<br><a href="mailto:Xymon@xymon.com">Xymon@xymon.com</a><br><a href="http://lists.xymon.com/mailman/listinfo/xymon" target="_blank">http://lists.xymon.com/mailman/listinfo/xymon</a><o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>