I agree. your command is much more concise and readable than what I originally came up with. Thanks.
On Wednesday, March 16, 2016 at 3:47:14 PM UTC+1, jcbollinger wrote: > > > > On Wednesday, March 16, 2016 at 6:32:02 AM UTC-5, Tony Gaetani wrote: >> >> The most-recently-modified file is not a resource managed by puppet, but >> I like how you're thinking. Maybe I find a way to configure this file >> (directory, actually) to be a puppet resource. Thanks for the idea. >> >> > Having the file you want to retain under management, either directly or > via recursive management of its directory, would be a decent direction to > go, but it might not be practical. If it isn't, then there is no resource > type among those shipped with Puppet that provides exactly what you want. > > If files are reliably added to the target directory on a fixed schedule, > however (e.g. old log files produced by logrotate), then you might be able > to use the Tidy's 'age' parameter to preserve the most recent one(s). > > There is also the option of writing a custom resource type to use in place > of Tidy. > > On the other hand, maybe it would ease the problem simply to use a cleaner > command in your Exec, such as > > ls -cd /dir/to/clean/* | grep 'subdir selection pattern' | sed 1d | xargs > rm -rf > > I guess beauty may be in the eye of the beholder, but I find that one a > lot easier to read than yours. Notes: > > 1. The -c option to ls causes the output to be sorted by ctime, from > newest to oldest. > 2. If you need extra help to distinguish directories from ordinary > files, you could add the -F option to the ls, so that a / will be > appended to directory names. You could then filter out non-directories > via > the grep pattern (or alternatively, by a slightly longer sed > program). The rm will ignore the trailing slash. > > > John > > -- 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 puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/727e4367-583c-47ad-bb6b-be8feefd69fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.