Dave LeFevre <dlef...@gmail.com> writes:
> I've helped him get started with all of this (we know how to use eval) but
> we are having some problems getting the last octet of the machine. Going
> through the cfengine docs I see that there are some ready made sys
> variables for getting the first, first two, or first three octets, but
> there are no documented sys variables for the other way around.
>
> Is getting that last octet something we would use a split for? Doing some
> string operations like this that would be easy in the shell are not
> something I have experience with when it comes to cfengine.
You can use string_split()
and nth()
to extract the last octet.
bundle agent main { vars: "last_octet[$(sys.ip_addresses)]" string => nth( string_split($(sys.ip_addresses), "\.", 4), 3); reports: "Running CFEngine $(sys.cf_version)"; "The last octect of '$(sys.ip_addresses)' is '$(last_octet[$(sys.ip_addresses)])'"; }
R: Running CFEngine 3.10.1 R: The last octect of '127.0.0.1' is '1' R: The last octect of '192.168.42.189' is '189' R: The last octect of '172.17.0.1' is '1' R: The last octect of '192.168.33.1' is '1'
–
Nick Anderson
Doer of things, CFEngine
You could do something like this in the vars: section
"fourth_octet" string => nth(splitstring("$(sys.ipv4)", "\.", "4"), 3);
However, I agree with Neil that this sounds like an XY problem. What
is your end goal? There might be a more
elegant way to do this.
On Mon, Apr 24, 2017 at 10:39 AM, Neil H. Watson
<cfen...@watson-wilson.ca> wrote:
> Kind of an XY problem. What is the higher end goal? Is the goal to have
> deterministic start time? CFEgine has some native time playing tools:
>
> https://docs.cfengine.com/docs/3.7/reference-functions-splayclass.html
> https://docs.cfengine.com/docs/3.10/reference-promise-types-classes.html#dist
>
> And some info on using CFEngine as cron:
> http://watson-wilson.ca/blog/tag/cron/
>
> --
> Neil H Watson @neil_h_watson
> CFEngine reporting: https://github.com/neilhwatson/delta_reporting
> CFEngine policy: https://github.com/neilhwatson/evolve_cfengine_freelib
> CFEngine and vim: https://github.com/neilhwatson/vim_cf3
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "help-cfengine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to help-cfengine+unsubscribe@googlegroups.com.
> To post to this group, send email to help-c...@googlegroups.com.
> Visit this group at https://groups.google.com/group/help-cfengine.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengine+unsubscribe@googlegroups.com.