I would like to have a tidy resource that deletes all files recursively 
from directories matching a pattern, except for the most recently modified 
file.


Something like this:


tidy {
  'clean up files except most recently modified one':
    path => '/path/to/files',
    recurse => true,
    rmdirs => true,
    age => '1h',
    matches => 'some-pattern',
    unless => '{bash script returning most recently modified file name}',
  ;
}


I understand that this is really stretching the scope of what tidy is for. 
That is why I have decided to just use an exec with a long line of bash 
that does what I want. However, this long and complicated line of bash code 
is not ideal for me because it is hard to understand and maintain, it's 
just kind of ugly:


# 1 - find all directories matching a pattern, print the most recently 
modified time and path
# 2 - sort by most recently modified
# 3 - remove the timestamp
# 4 - remove the last item
# 5 - rm -rf all of the paths
find /path/to/files -maxdepth 1 -type d -name 'some*pattern' -printf '%T+ 
%p\n' | sort | cut -d' ' -f2 | head -n -1 | xargs rm -rf


Even if tidy is not an option, does anyone else have any better ideas than 
my exec?

Thanks in advance
-Tony

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" 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/puppet-users/3962a82f-536a-49ef-ad57-ddd872d4ba6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to