I tried removing the log files with:
log 'remove compressed log files'
::Dir['/var/log/*.gz'].each { |f| ::FileUtils.rm_rf(f) }
My request is to remove them based to mtime.
This is just plain Ruby code, not the Chef recipe DSL. A more Chef-ish way to do this would be
Dir['/var/log/*.gz'].each do |path|
file path do
action :delete
only_if { ::File.stat(path).ctime < (Time.now - 60*60*24*7) }
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With