B
Brad Winborg
This is the script, it's intent is to read all Error logs.txt files in a
directory or just the text files that are listed. Find all the lines
that contain the word "error" and all the lines that contain the word
"warning" display a count of each word. Additionally it should create
report that tells how many times the two words appear every ten min, for
the duration of the error logs.
my_path = "D:\My Documents\\Replicon\\log_file_20090221_041817.txt"
warning = 0
error = 0
d = Dir.new(my_path)
d.each do |fl|
unless fl == '.' or fl == '..' then
puts my_path + fl
File.open(my_path + fl, "r").each do |line|
if line =~ /error/ then
error += 1
elsif line =~ /warning/ then
warning += 1
end
end
end
end
puts warning.to_s
puts error.to_s
Here is the errors I receive when I run it.
Not a directory - D:\My Documents\Replicon\log_file_20090221_041817.txt\
D:/My Documents/Replicon/ErrorCount.rb:6:in `initialize'
Press ENTER to close the window...
Directory Path
D:\My Documents\Replicon
I was going to add an attachment to show that the directory really exits
and that the file is in that directory, but it was to large.
If anyone has any ideas as to why it is not working I be very grateful,
as I am new to ruby code in general.
directory or just the text files that are listed. Find all the lines
that contain the word "error" and all the lines that contain the word
"warning" display a count of each word. Additionally it should create
report that tells how many times the two words appear every ten min, for
the duration of the error logs.
my_path = "D:\My Documents\\Replicon\\log_file_20090221_041817.txt"
warning = 0
error = 0
d = Dir.new(my_path)
d.each do |fl|
unless fl == '.' or fl == '..' then
puts my_path + fl
File.open(my_path + fl, "r").each do |line|
if line =~ /error/ then
error += 1
elsif line =~ /warning/ then
warning += 1
end
end
end
end
puts warning.to_s
puts error.to_s
Here is the errors I receive when I run it.
Not a directory - D:\My Documents\Replicon\log_file_20090221_041817.txt\
D:/My Documents/Replicon/ErrorCount.rb:6:in `initialize'
Press ENTER to close the window...
Directory Path
D:\My Documents\Replicon
I was going to add an attachment to show that the directory really exits
and that the file is in that directory, but it was to large.
If anyone has any ideas as to why it is not working I be very grateful,
as I am new to ruby code in general.