#!/usr/bin/ruby -w # A script to remove all users that haven't added an advert the last month. # This program is specially made for Kim Johanssons Buy/Sell-site ViHandla.se require "mysql" require "pp" # Check if host, user, password and database is supplied via cli. if ARGV.include?("--help") then STDERR.puts("vh_clean --host=localhost --user=root --passwd=hello --db=root") STDERR.puts("vh_clean -h=localhost -u=root -p=hello -d=root") STDERR.puts("To use one of the ") exit 1 end class Config public def file if File.exists?(ENV["HOME"] + "/.vhrc") file = ENV["HOME"] + "/.vhrc" file = File.open(file) while line = file.gets if line =~ /^(^#).*/ lines[] = line end end return lines elsif File.exists?("/etc/vhrc") file = "/etc/vhrc" file = File.open(file) while line = file.gets if line =~ /^(^#).*/ lines[] = line end end return lines end end public def args unless ARGV.empty? max = ARGV.length i = 0 args = Hash.new ARGV.each do x = i + 1 if ARGV[i] =~ /--[a-zA-Z0-9]+/ && ARGV[x] =~ /[a-z0-9A-Z]+/ args[ARGV[i]] = ARGV[x] elsif ARGV[i] =~ /--[a-zA-Z0-9]+/ args[ARGV[i]] = ARGV[i] end i += 1 end end return args end public def get_setting pp(self.args) pp(self.file) end end conf = Config.new conf.get_setting #begin # dbh = Mysql.real_connect(db_host, db_user, db_passwd, db_db) # puts("Server version: " + dbh.get_server_info) #rescue Mysql::Error => e # puts("Error code: #{e.errno}") # puts("Error message: #{e.error}") # puts("Error SQLSTATE #{e.sqlstate}") if e.responds_to?("sqlstate") #ensure # dbh.close if dbh #end