Detect a file changes then execute a command

80 views
Skip to first unread message

cfday

unread,
Aug 28, 2014, 9:06:03 AM8/28/14
to help-c...@googlegroups.com
cfengine is as you know able to detect if a file or even directories have changed.

Example from the online documentation:
bundle agent example { files: "/etc/example" # Directory to monitor for changes. changes => detect_all_change, depth_search => recurse("inf"); } ######################################################### body changes detect_all_change { report_changes => "all"; update_hashes => "yes"; }

cfengine will notice the changes and inform me.
Is it possible not only to raise a warning if there were changes but rather to execute a command, e.g. a script? Maybe it will help classes => if_repaired("changes") in the file promise?

Nick Anderson

unread,
Aug 28, 2014, 9:43:24 AM8/28/14
to help-c...@googlegroups.com
On 08/28/2014 08:06 AM, cfday wrote:
> Is it possible not only to raise a warning if there were changes but
> rather to execute a command, e.g. a script? Maybe it will help
> classes => if_repaired("changes") in the file promise?

Yes the following example should work for you.

#########################################################
bundle agent example
{
files:
"/etc/example" # Directory to monitor for changes.
changes => detect_all_change,
depth_search => recurse("inf"),
classes => scoped_classes_generic("bundle", "etc_example");

commands:
etc_example_repaired::
"/bin/echo"
args => "Run a command";

}
#########################################################
body changes detect_all_change
{
report_changes => "all";
update_hashes => "yes";
}
#########################################################

Additionally I believe there are automatic classes that are defined when
changes are detected. Unfortunately I am unable to find reference to
those in the documentation.

cfday

unread,
Sep 1, 2014, 5:12:19 AM9/1/14
to help-c...@googlegroups.com
I need it only for one file. But yes, indeed! If the content of the file has changed, a class will be set and depending on a command is started.
Reply all
Reply to author
Forward
0 new messages