Delete all subdirectories (recursively), except a few
Bob <[email protected]> Tue, 30 Apr 2024 14:46:47 -0700 (PDT)
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
I have to manage a directory that many people can create subdirectories and
files.
Let's say the directory is "/srv/data". I would like to remove any other
directories created (recursively) that are older than 7 days and not is a
predefined list. I can't quite get there.
bundle agent main
{
vars:
linux::
"keep_dirs" slist => { "project1", "project2", "etc" };
files:
linux:
"/srv/data"
delete => tidy,
file_select => exclude_name_age_dir("@(keep_dirs)", "7");
depth_search => recurse("inf");
}
body file_select exclude_name_age_dir(name,days)
{
leaf_name => { "$(name)" };
mtime => irange(0,ago(0,0,"$(days)",0,0,0));
file_types => { "dir" };
file_result => "file_types.mtime.!leaf_name";
}
This will delete any folders that are empty, but doesn't quite do what I
need.
I appreciate any suggestions.
--
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 [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/2991fbc6-a151-43ea-aa27-a0d8f20a38fdn%40googlegroups.com.