multiline regex check? (check if satellite-tools repo is enabled in multi-repo file redhat.repo)

17 views
Skip to the first unread message

Aleksey Tsalolikhin

unread,
20 Dec 2017, 23:27:3020/12/2017
to help-cfengine
Is there any way to do a multiline regex check in CFEngine?

I want to check if the Red Hat Satellite Tools repo definition in /etc/yum.repos.d/redhat.repo is enabled (enabled = 1).  

There are multiple repo definitions in that file.

I am trying to make that check (to see if the satellite-tools repo is enabled) lighter weight.

For example:

# time (yum repolist | grep satellite-tools)
rhel-6-server-satellite-tools-6.2-rpms Red Hat Satellite Tools 6.2 (for R    115

real    0m1.347s
user    0m0.583s
sys     0m0.074s
# time (awk '/satellite-tools/,/enabled/' /etc/yum.repos.d/redhat.repo | grep 'enabled = 1')
enabled = 1

real    0m0.002s
user    0m0.001s
sys     0m0.001s
#

I am trying to keep the CFEngine agent resource utilization footprint small so people don't complain about cf-agent showing up using 100% CPU in "top".  I haven't had any such complaints for over a year and I don't want to start getting them again.   :)

Thanks!
Aleksey


--
Achieve real learning.  Email trai...@verticalsysadmin.com.

nick.a...@northern.tech

unread,
20 Dec 2017, 23:57:3920/12/2017
to help-cfengine, Aleksey Tsalolikhin
--
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-cfengin...@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.

Aleksey Tsalolikhin

unread,
21 Dec 2017, 06:24:3521/12/2017
to Nick Anderson, help-cfengine
Yeah, I tried regcmp() but "it didn't work". I'll try again.  Now I know I'm on the right track.  Thanks, Nick!

-- 
Achieve real learning.  Email trai...@verticalsysadmin.com.

To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengine+unsubscribe@googlegroups.com.

Neil H. Watson

unread,
21 Dec 2017, 09:21:4621/12/2017
to help-cfengine

Nick Anderson

unread,
21 Dec 2017, 14:05:4821/12/2017
to Neil H. Watson, help-cfengine
Aleksey is this what you were trying to do?


#+Name: Example showing how to search for a mutliline pattern in a file using native functions
#+Caption: Example showing how to search for a mutliline pattern in a file using native functions
#+BEGIN_SRC cfengine3
  bundle agent main
  {
        # CFEngine
        # is the agent you're looking for.

    files:
      "/tmp/example.txt"
        create => "true",
        edit_line => insert_lines( "CFEngine$(const.n)is the agent you're looking for" );

    vars:

        "file_content"
          string => readfile( "/tmp/example.txt" , inf ),
          if => not( isvariable( $(this.promiser) ) );

    classes:

        # Search for a multi-line string
        "I_found_the_agent_i_am_looking_for"
          expression => regcmp( "CFEngine\Ris\sthe\sagent.*",
                                $(file_content));

        "I_did_not_find_droids"
          expression => not( regcmp( ".*droid.*",
                                $(file_content)));


    reports:

        "CFEngine $(sys.cf_version)";

        "/tmp/example.txt contains:$(const.n)$(file_content)";

        "I found the agent i'm looking for."
          if => "I_found_the_agent_i_am_looking_for";

        "I see no droids."
          if => "I_did_not_find_droids";
  }
#+END_SRC

Results in this output:

#+RESULTS: Example showing how to search for a mutliline pattern in a file using native functions
: R: CFEngine 3.11.0
: R: /tmp/example.txt contains:
: CFEngine
: is the agent you're looking for
:
: R: I found the agent i'm looking for.
: R: I see no droids.



On Thu, Dec 21, 2017 at 8:21 AM, Neil H. Watson <cfen...@watson-wilson.ca> wrote:
--
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.
Reply all
Reply to author
Forward
0 new messages