Skip to content

Instantly share code, notes, and snippets.

@coderforhire
Created December 8, 2011 17:43
Show Gist options
  • Save coderforhire/1447771 to your computer and use it in GitHub Desktop.
Save coderforhire/1447771 to your computer and use it in GitHub Desktop.
task :cron => :environment do
puts "Pulling new requests..."
counter = 1
file = File.new("/home/test/rails_projects/RubyScripts/secure", "r")
while (line = file.gets)
if line.match(/Accepted publickey for/)
line_to_breakdown = line
login_time = line_to_breakdown.match(/[A-Z][a-z][a-z]\s\s\d\s\d\d:\d\d:\d\d/).to_s
@last_login_time = Time.parse(login_time).to_i
last_login = @last_login_time.to_s
ip_address = line_to_breakdown.match(/(\d{1,3}\.){3}\d{1,3}/)
venue = line_to_breakdown.match(/[a-z]\d\d\d\d[\s\S]/)
Appliance.create!(:venue => "#{venue}", :last_login => "#{last_login}", :ip_address => "#{ip_address}")
end
counter = counter + 1
puts counter
end
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment