Xymon Mailing List Archive search

File monitoring with `date` in filename

7 messages in this thread

list Rolf Schrittenlocher · Thu, 26 Sep 2013 09:34:11 +0200 ·
Dear xymon users,

I got stuck while trying to monitor a file which should be updated 
regularly and which has got a timestamp in its name.
"files" on the server remains clear, no data . Could someone tell me 
what is wrong with these settings or what have i forgotten?

On the server we have in
analysis.cfg
HOST=myserver
  FILE    `/home/mypath/log/update_out_$(date +%Y%m%d).txt` MTIME<600 red

in client-local.cfg:
[myserver]
   file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`


I see an entry for this file on the client
in tmp logfetch.myserver.cfg
   file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`

but there is nothing for this file in msg.myserver.txt

File exists and is readable:
   find /home/mypath/log/update_out_$(date +%Y%m%d).txt   -exec ls -l {} \;
   -rw-rw-r--   1 ...      2467070 Sep 26 08:43 
/home/mypath/log/update_out_20130926.txt

In xymonclient.log I see an entry
sh: syntax error at line 1: `(' unexpected
but I don't know if it is related to the file problem or to anything else.
I know that sh can't deal with $(xy), I tried as well
FILE    /home/mypath/log/update_out_`date +%Y%m%d`.txt MTIME<600 red
but in vain.

Any help appreciated,
kind regards
Rolf


-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid
Persoenlich: user-4b3b4051a09b@xymon.invalid
list Deepak Deore · Thu, 26 Sep 2013 14:34:28 +0530 ·
Looks like your analysis.cfg entry is wrong.Try this.

FILE    /home/mypath/log/update_out_[0-9]*-[0-9]*-[0-9]*\.txt MTIME<600 red


On Thu, Sep 26, 2013 at 1:04 PM, Rolf Schrittenlocher <
quoted from Rolf Schrittenlocher
user-4b3b4051a09b@xymon.invalid> wrote:
Dear xymon users,

I got stuck while trying to monitor a file which should be updated
regularly and which has got a timestamp in its name.
"files" on the server remains clear, no data . Could someone tell me what
is wrong with these settings or what have i forgotten?

On the server we have in
analysis.cfg
HOST=myserver
 FILE    `/home/mypath/log/update_out_$**(date +%Y%m%d).txt` MTIME<600 red

in client-local.cfg:
[myserver]
  file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`


I see an entry for this file on the client
in tmp logfetch.myserver.cfg
  file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`

but there is nothing for this file in msg.myserver.txt

File exists and is readable:
  find /home/mypath/log/update_out_$(**date +%Y%m%d).txt   -exec ls -l {}
\;

  -rw-rw-r--   1 ...      2467070 Sep 26 08:43 /home/mypath/log/update_out_
**20130926.txt
quoted from Rolf Schrittenlocher

In xymonclient.log I see an entry
sh: syntax error at line 1: `(' unexpected
but I don't know if it is related to the file problem or to anything else.
I know that sh can't deal with $(xy), I tried as well
FILE    /home/mypath/log/update_out_`**date +%Y%m%d`.txt MTIME<600 red
but in vain.

Any help appreciated,
kind regards
Rolf


--
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid
Persoenlich: user-4b3b4051a09b@xymon.invalid

______________________________**

Xymon at xymon.com<
list Rolf Schrittenlocher · Thu, 26 Sep 2013 13:44:00 +0200 ·
Thanks Deepak,

unfortunately that won't help as I need the file with the present date 
in its name.  I did now:
`ls -tr /home/mypath/log/update_out_*.txt|tail -1`
This workaround helped. But I'm still curious if there is a solution for 
first expanding the date and second the whole expression
`find /home/mypath/log/update_out_$(date +%Y%m%d).txt`  (sorry, I 
dropped the find in my first posting)

kind regards
Rolf
quoted from Deepak Deore


Looks like your analysis.cfg entry is wrong.Try this.

FILE    /home/mypath/log/update_out_[0-9]*-[0-9]*-[0-9]*\.txt MTIME<600 red


On Thu, Sep 26, 2013 at 1:04 PM, Rolf Schrittenlocher 
<user-4b3b4051a09b@xymon.invalid <mailto:user-4b3b4051a09b@xymon.invalid>> wrote:

    Dear xymon users,

    I got stuck while trying to monitor a file which should be updated
    regularly and which has got a timestamp in its name.
    "files" on the server remains clear, no data . Could someone tell me
    what is wrong with these settings or what have i forgotten?

    On the server we have in
    analysis.cfg
    HOST=myserver
      FILE    `/home/mypath/log/update_out_$(date +%Y%m%d).txt`
    MTIME<600 red

    in client-local.cfg:
    [myserver]
       file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`


    I see an entry for this file on the client
    in tmp logfetch.myserver.cfg
       file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`

    but there is nothing for this file in msg.myserver.txt

    File exists and is readable:
       find /home/mypath/log/update_out_$(date +%Y%m%d).txt -exec ls -l
    {} \;
       -rw-rw-r--   1 ...      2467070 Sep 26 08:43
    /home/mypath/log/update_out_20130926.txt

    In xymonclient.log I see an entry
    sh: syntax error at line 1: `(' unexpected
    but I don't know if it is related to the file problem or to anything
    else.
    I know that sh can't deal with $(xy), I tried as well
    FILE    /home/mypath/log/update_out_`date +%Y%m%d`.txt MTIME<600 red
    but in vain.

    Any help appreciated,
    kind regards
    Rolf


    -- 
    Mit freundlichen Gruessen
    Rolf Schrittenlocher

    Lokales Bibliothekssystem Frankfurt
    Senckenberganlage 31, 60054 Frankfurt
    Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX

    LBS: user-1e39a1813094@xymon.invalid <mailto:user-1e39a1813094@xymon.invalid>
    Persoenlich: user-4b3b4051a09b@xymon.invalid
quoted from Deepak Deore

    
-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid
Persoenlich: user-4b3b4051a09b@xymon.invalid
list Rolf Schrittenlocher · Thu, 26 Sep 2013 14:45:52 +0200 ·
Hi Mark,

thanks, but this doesn't work either. I assume the problem is that the backticks are evaluated, but the "$(date)" isn't as that is done by sh and sh doesn't know $(variable). So what we need is some thing like  one backtick expansion after the other. or a way to let ksh do the job. But I don't know if there is way to achieve that.

The workaround is ok for the moment. If the log is missing it wouldn't be very serious as we are checking for MTIME<600 (last access more then 10 minutes ago). So xymon will get red in case todays file is missing as it is older than that,
kind regards
Rolf
Wonder if you need to preface the operation with an eval to get the date command to operate first -- don't know if this will work with Xymon.

FILE `eval find /home/mypath/log/update_out_$(date +%Y%m%d).txt` MTIME<red

The other thing I would be a little leery of, is having any expression calculation in the filepath variable in the find command -- some older Unix flavors may get upset over this syntax. Calculations/regex tend to be better supported with the --name attribute. Ditto with presumed output versus need to use "-print " in older find commands. If you don't need to support older Unix flavors, then ignore all of this.

FILE `eval find /home/mypath/log --name "update_out_$(date +%Y%m%d).txt" --print` MTIME<red

Above would need more work though as by itself it will keep hunting down the log directory tree for possibly other files.

The thing I don't particular care for with `ls --tr /home/mypath/log/update_put_*.txt| tail -1` is what happens if the current day's file is missing? Then you are parsing yesterday's or the last log file. No complaints if the wrong file is being operated on.  Would ~assume you want some kind of alert if the today's log file is missing....

*From:*Xymon [mailto:xymon-bounces at xymon.com] *On Behalf Of *Rolf Schrittenlocher
*Sent:* Thursday, September 26, 2013 7:44 AM
*To:* deepak deore
*Cc:* xymon
*Subject:* Re: [Xymon] File monitoring with `date` in filename
quoted from Rolf Schrittenlocher

Thanks Deepak,

unfortunately that won't help as I need the file with the present date in its name.  I did now:
`ls -tr /home/mypath/log/update_out_*.txt|tail -1`
This workaround helped. But I'm still curious if there is a solution for first expanding the date and second the whole expression
`find /home/mypath/log/update_out_$(date +%Y%m%d).txt` (sorry, I dropped the find in my first posting)

kind regards
Rolf


Looks like your analysis.cfg entry is wrong.Try this.

FILE    /home/mypath/log/update_out_[0-9]*-[0-9]*-[0-9]*\.txt MTIME<600 red

On Thu, Sep 26, 2013 at 1:04 PM, Rolf Schrittenlocher <user-4b3b4051a09b@xymon.invalid <mailto:user-4b3b4051a09b@xymon.invalid>> wrote:

Dear xymon users,

I got stuck while trying to monitor a file which should be updated regularly and which has got a timestamp in its name.
"files" on the server remains clear, no data . Could someone tell me what is wrong with these settings or what have i forgotten?

On the server we have in
analysis.cfg
HOST=myserver
 FILE    `/home/mypath/log/update_out_$(date +%Y%m%d).txt` MTIME<600 red

in client-local.cfg:
[myserver]
  file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`


I see an entry for this file on the client
in tmp logfetch.myserver.cfg
  file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`

but there is nothing for this file in msg.myserver.txt

File exists and is readable:
  find /home/mypath/log/update_out_$(date +%Y%m%d).txt -exec ls -l {} \;
  -rw-rw-r--   1 ...      2467070 Sep 26 08:43 /home/mypath/log/update_out_20130926.txt

In xymonclient.log I see an entry
sh: syntax error at line 1: `(' unexpected
but I don't know if it is related to the file problem or to anything else.
I know that sh can't deal with $(xy), I tried as well
FILE    /home/mypath/log/update_out_`date +%Y%m%d`.txt MTIME<600 red
but in vain.

Any help appreciated,
kind regards
Rolf


-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid <mailto:user-1e39a1813094@xymon.invalid>

Persoenlich: user-4b3b4051a09b@xymon.invalid <mailto:user-4b3b4051a09b@xymon.invalid>
quoted from Rolf Schrittenlocher


-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher
  Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX

LBS:user-1e39a1813094@xymon.invalid  <mailto:user-1e39a1813094@xymon.invalid>
Persoenlich:user-4b3b4051a09b@xymon.invalid  <mailto:user-4b3b4051a09b@xymon.invalid>  
quoted from Rolf Schrittenlocher

-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid
Persoenlich: user-4b3b4051a09b@xymon.invalid
list Jeremy Laidman · Fri, 27 Sep 2013 11:37:48 +1000 ·
On 26 September 2013 17:34, Rolf Schrittenlocher <
quoted from Rolf Schrittenlocher
user-4b3b4051a09b@xymon.invalid> wrote:
On the server we have in
analysis.cfg
HOST=myserver
 FILE    `/home/mypath/log/update_out_$**(date +%Y%m%d).txt` MTIME<600 red
You cannot use backticks in analysis.cfg FILE patterns.  You have to use a
pattern match or a regular expression.  So one of these might work for you:

FILE    "/home/mypath/log/update_out_*.txt" MTIME<600 red

or

FILE    "%/home/mypath/log/update_out_[0-9]*\.txt" MTIME<600 red

These should match whatever file is evaluated by the backtick expression in
analysis.cfg.  That will only ever be one file, so you should only see
alarms for the correct file.

in client-local.cfg:
[myserver]
  file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`
If your Xymon user's shell is bourne shell, then the $() form won't work.
 Bourne shell uses only backticks, but you cannot use backticks either,
because Xymon terminates the "file:" expression at the second backtick.

You can probably just run bash, if it's installed, and give it the command
you want, using the $() expression, like so:

file:`bash -c 'find /mypath/log/update_out_$(date +%Y%m%d).txt'`
quoted from Rolf Schrittenlocher

In xymonclient.log I see an entry
sh: syntax error at line 1: `(' unexpected
but I don't know if it is related to the file problem or to anything else.
Yes, this is bourne shell complaining about "(" following "$" because it
requires an opening paren to be at the start of an expression.  It doesn't
understand "$().  So try the "bash" thing and see if it works for you.  If
bash isn't installed, then the same should work for korn shell (ksh).

J
list Rolf Schrittenlocher · Fri, 27 Sep 2013 09:27:31 +0200 ·
Hi,

thanks a lot to all and especially to you, Jeremy. The central info was "You cannot use backticks in analysis.cfg FILE patterns".
I still have no idea what the bourne shell is doing on the client. Xymon user uses bash, maybe the error is the result of some other script using sh and not related to the file problem.
But at least it is working know and I know how to set entries in analysis.cfg and client-local.cfg

Rolf

This is what I use now
analysis.cfg: FILE    `/home/mypath/log/update_out_$(date +%Y%m%d).txt` MTIME<600 red
client config.cfg: file:`bash -c 'find /mypath/log/update_out_$(date +%Y%m%d).txt'`
quoted from Rolf Schrittenlocher
On 26 September 2013 17:34, Rolf Schrittenlocher <user-4b3b4051a09b@xymon.invalid <mailto:user-4b3b4051a09b@xymon.invalid>> wrote:

    On the server we have in
    analysis.cfg
    HOST=myserver
     FILE    `/home/mypath/log/update_out_$(date +%Y%m%d).txt`
    MTIME<600 red


You cannot use backticks in analysis.cfg FILE patterns.  You have to use a pattern match or a regular expression.  So one of these might work for you:

Live in San Francisco
quoted from Jeremy Laidman

or

FILE    "%/home/mypath/log/update_out_[0-9]*\.txt" MTIME<600 red

These should match whatever file is evaluated by the backtick expression in analysis.cfg.  That will only ever be one file, so you should only see alarms for the correct file.

    in client-local.cfg:
    [myserver]
      file:`find /mypath/log/update_out_$(date +%Y%m%d).txt`


If your Xymon user's shell is bourne shell, then the $() form won't work.  Bourne shell uses only backticks, but you cannot use backticks either, because Xymon terminates the "file:" expression at the second backtick.

You can probably just run bash, if it's installed, and give it the command you want, using the $() expression, like so:

file:`bash -c 'find /mypath/log/update_out_$(date +%Y%m%d).txt'`

    In xymonclient.log I see an entry
    sh: syntax error at line 1: `(' unexpected
    but I don't know if it is related to the file problem or to
    anything else.


Yes, this is bourne shell complaining about "(" following "$" because it requires an opening paren to be at the start of an expression.  It doesn't understand "$().  So try the "bash" thing and see if it works for you.  If bash isn't installed, then the same should work for korn shell (ksh).

J
-- 
Mit freundlichen Gruessen
Rolf Schrittenlocher

Lokales Bibliothekssystem Frankfurt
Senckenberganlage 31, 60054 Frankfurt
Tel: (XX) XX - XXX XXXXX   Fax: (XX) XX XXX XXXXX
LBS: user-1e39a1813094@xymon.invalid
Persoenlich: user-4b3b4051a09b@xymon.invalid
list Jeremy Laidman · Fri, 27 Sep 2013 17:47:58 +1000 ·
On 27 September 2013 17:27, Rolf Schrittenlocher <
quoted from Rolf Schrittenlocher
user-4b3b4051a09b@xymon.invalid> wrote:
I still have no idea what the bourne shell is doing on the client. Xymon
user uses bash, maybe the error is the result of some other script using sh
and not related to the file problem.

I think I worked it out.  The first line in "xymonclient.sh" is
"#!/bin/sh".  So doesn't matter what the xymon user's shell is, the script
runs under bourne shell.  Under Linux, /bin/sh is actually a symlink to
bash so the $() works.  But on other systems where /bin/sh is actually a
real bourne shell, you gotta do the bash work-around.

J