Forum: Cfengine Help
Subject: Re: Cfengine time handling
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,21606,21619#msg-21619
Ok, so after posting, I figured I should just test it myself instead of waiting
for someone else. :)
me@host
$ cat /tmp/test.cf
body common control{ bundlesequence => { "a" }; }
bundle common a{
vars:
"minute" int => accumulated(0,0,0,0,1,0);
"on" int => on(1970,1,1,0,0,0);
"now" int => now();
"ago" int => ago(0,0,0,0,0,1);
reports:
linux|!linux::
"Minute is '$(minute)'";
"On is '$(on)'";
"Now is '$(now)'";
"Ago is '$(ago)'";
}
me@host
$ cf-agent -f /tmp/test.cf
R: Minute is '60'
R: On is '21600'
R: Now is '1303846784'
R: Ago is '1303846783'
So, the integer time format is a Unix time stamp. Accumulated() differs from
On() by around 1970 years (duh). On() uses the local time, not GMT, which makes
sense. Marginally interestingly, the value returned by On(1970,1,1,0,0,0) is
not neccesarily the date which localtime(0) returns in your locale.
me@host
$ perl -le'print scalar localtime 0'
Wed Dec 31 18:00:00 1969
So, although there's probably not a practical difference in most cases, you
need to use a 0 instead of the result of on() with the Unix epoch to, for
example, catch files created with a screwed-up timestamp of 0. The thing I
posted above with "irange(0,$(amonthago))" would therefore be the "right" way
to find everything older than a month.
And, with that, there's something that might be useful for someone using the
same search terms that I used before, which returned no hits. :)
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine