On Sun, Dec 9, 2012 at 2:35 AM, Krzysztof Kowalski <[email protected]> wrote:
> Hello there.
> I would like to make script that gets failed logging attempt ip, when it
> count that ip tried logging more than 5 times in row script will write new
> block rule with that ip to ipfilter in freebsd 8.
> So I like to manage this by getting each line of file with logging attempts
> to arrays ( it makes array in array). I have a little problem with obtaining
> array with word "Failed" and passing it to new array with ip's that i would
> like to block. Next I get every 13th element (which is ipv6 address) and
> write new rule after counting it with hash.
> Can someone show me how to make it happend?
>
> CODE:
> #!/usr/local/bin/ruby19
> filename = '/var/log/auth.log'
> falo = String.new
That String creation is superfluous since the reference will be
overwritten anyway. You can instead do
falo = File.open(filename) { |f| f.read }
> File.open(filename) { |f| falo = f.read }
> words = falo.split('\n')
words actually holds lines.
The whole code can be condensed to
words = File.readlines(filename).each(&:chomp!)
or
words = File.foreach(filename).map(&:chomp)
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en