Tidying files based on size and age

226 views
Skip to first unread message

James T.

unread,
Sep 27, 2013, 11:31:16 AM9/27/13
to help-c...@googlegroups.com
How can I tidy files based on size and age? For example, I would like to delete files in /var/cfengine/outputs that are older than 90 days AND less 200 bytes in size. 

The code below deletes output files older than 90 days, but I'm not sure how to combine it with a size restriction.

 files:
    any::
        # cleanup old logs
        "$(sys.workdir)/outputs"
        comment                 => "Clean up outputs older than 90 days",
        delete                  => tidy,
        file_select             => days_old("90");


Brian Bennett

unread,
Sep 27, 2013, 11:34:47 AM9/27/13
to James T., help-c...@googlegroups.com
Instead of using the built in days_old body, create a new one that selects based on size and age. And use that one instead. Use days_old as an example to create the new one.

-- 
Brian
--
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 http://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/groups/opt_out.

James T.

unread,
Sep 27, 2013, 12:46:45 PM9/27/13
to help-c...@googlegroups.com, James T.
Good idea. This is what I ended up using:


# tidy old files based on age and size
body file_select file_days_size(days,from,to) {
        search_size     => irange("$(from)","$(to)");
        mtime           => irange(0,ago(0,0,"$(days)",0,0,0));
        file_result     => "((mtime)&(size))";
}


 files:
    any::
        # cleanup old logs
        "$(sys.workdir)/outputs"
        comment                 => "Clean outputs older than 60 days and < 200 bytes",
        delete                  => tidy,
        file_select             => file_days_size("60", "0", "200");




Reply all
Reply to author
Forward
0 new messages