#!/usr/bin/env ruby

# encoding: utf8

require 'find'

def get_baseline (cond) baseline = Time.now.to_i - cond; end

def clearlog (dir, cond=172800)
    baseline = get_baseline cond

    Find.find(dir) do |path|
        # leveldb give .log extension to its data file
        if path =~ /\/root\/ubs\/storage/
                puts "skip #{path}"
                next
        end

        if path =~ /\.(log)$/
            mtime = (File.mtime path).to_i
            if mtime < baseline
                begin
                    puts "delete #{path}"
                    File.delete path
                rescue
                    puts "failed to delete #{path}"
                end
            end
        end
    end
end

clearlog '/root'
#clearlog '/srv/http/uwebsite/www/application/logs'

# vim:set ts=4 sw=4 et: