Delete all files in a directory older than x days with the help of a chef
I tried to delete 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 on mtime.
+3
nithin sunny
source
to share
1 answer
This is just regular Ruby code, not a DSL chef's recipe. The more chef-ish way to do it 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
+5
coderanger
source
to share