Recursive delete select files more than 60 days old

12 views
Skip to first unread message

Bob

unread,
Aug 28, 2015, 4:58:33 PM8/28/15
to help-cfengine
I've made a few attempts at this, but it's not working.  I have a structure like this:

/srv/data/dataset1
/srv/data/test1_prog1_123
/srv/data/test2_prog1_5442
/srv/data/test3_prog1_123
/srv/data/test4_prog2_6773

I need to get rid of the stuff with .*_prog1_.* and .*_prog2_.* in it, but leave the other stuff.  Here's my last attempt:

bundle agent sitemain
{
vars:
      "prog_logs" slist => { ".*_prog1_.*/.*", ".*_prog2_.*/.*" };

files:
  data_sys::
    "/srv/data"
    delete        => tidy,
    file_select   => name_age("@(sitemain.prog_logs)", "60"),
    depth_search => recurse("inf");
}


The issue is nothing is being removed. Here's what I see in the log:

cf3>  ->>  Entering /srv/data/test1_prog1_123 (0)

but never any deletes.

Neil Watson

unread,
Aug 28, 2015, 6:42:47 PM8/28/15
to help-cfengine
Note enough data provided. But, leaf name only matches the file node, not
the directories. Also, your regexes are far to loose and greedy. Tighten
them up and test with pcregrep or gnu grep -P.

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Ted Zlatanov

unread,
Sep 8, 2015, 1:25:07 PM9/8/15
to help-c...@googlegroups.com
On Fri, 28 Aug 2015 13:58:33 -0700 (PDT) Bob <buha...@gmail.com> wrote:

B> I've made a few attempts at this, but it's not working. I have a structure
B> like this:

B> /srv/data/dataset1
B> /srv/data/test1_prog1_123
B> /srv/data/test2_prog1_5442
B> /srv/data/test3_prog1_123
B> /srv/data/test4_prog2_6773

B> I need to get rid of the stuff with .*_prog1_.* and .*_prog2_.* in it, but
B> leave the other stuff.

You could build the slist of such files with findfiles()

https://docs.cfengine.com/latest/reference-functions-findfiles.html

So `/srv/data/test/*_prog[12]_*` might work for you.

Ted

Reply all
Reply to author
Forward
0 new messages