# Actually run the thing. require 'src/janitor' require 'optparse' # Set up the default options options = { :apache_vhost_directory => '/etc/apache2/vhosts.d', :maximum_file_age => 7 } # And parse any that were given on the command line. OptionParser.new do |opts| opts.banner = "Usage: #{$0} [options]" opts.on('-a', '--apache_vhosts_directory VHOSTS_DIR', 'Apache vhost conf file directory') do |vhost_dir| options[:apache_vhost_directory] = vhost_dir end opts.on('-m', '--maximum_file_age MAX_DAYS_OLD', Integer, 'Maximum file age (in days)') do |max_age| options[:maximum_file_age] = max_age end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! # Print an informational header every time the program is run. puts "Command line: #{$0 + ' ' + ARGV.join(' ')}" current_time = Time.now() if current_time.respond_to?(:iso8601) # Somehow this method is missing on some machines. puts "Time: #{current_time.iso8601}" else # Fall back to whatever this looks like. puts "Time: #{current_time}" end puts "Apache vhost directory: #{options[:apache_vhost_directory]}" puts "Max File Age: #{options[:maximum_file_age]}" j = Janitor.new() j.apache_vhosts_directory = options[:apache_vhost_directory] temp_dirs = j.get_temporary_directories() puts "Temporary directories: #{temp_dirs.join(', ')}\n\n" temp_dirs.each do |dir| j.clean_directory(dir, options[:maximum_file_age]) end