# Ruby scripting

**URL:** <https://www.ruby-forum.com/t/ruby-scripting/161477>\
**Category:** Ruby\
**Created:** [February 26, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477 "2009-02-26T20:35:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwinborg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/51bf81/32.png) [@bwinborg](https://www.ruby-forum.com/u/bwinborg)\
**Post date:** [February 26, 2009, 8:35pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477/1 "2009-02-26T20:35:02Z")

</div>

Ruby scripting - I am just starting to learn Ruby and I wanted to know  
if anyone out there knows it well. I am trying to do a project and I  
have run into a problem.

I have an executable file that when run creates (n) number of error  
logs. So from a command prompt you run the ,exe with with (n) being the  
number of logs you wish to create. We will make n =10. Then using ruby  
create a program that will search through those 10 error logs and find  
and display how many times the word error is found and how many times  
the word warning is found. Then Produce a report showing the number of  
error and warning log messages for 10-minute over the entire length of  
time represented by the generated log files.

---

<div class="post-metadata">

**Author:** ![bwinborg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/51bf81/32.png) [@bwinborg](https://www.ruby-forum.com/u/bwinborg)\
**Post date:** [February 26, 2009, 8:41pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477/2 "2009-02-26T20:41:18Z")

</div>

On Thu, Feb 26, 2009 at 12:34 PM, Brad W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> error and warning log messages for 10-minute over the entire length of  
> time represented by the generated log files.

sounds rather like a homework assignment …

what have you tried so far?

---

<div class="post-metadata">

**Author:** ![bwinborg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/51bf81/32.png) [@bwinborg](https://www.ruby-forum.com/u/bwinborg)\
**Post date:** [February 26, 2009, 8:44pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477/3 "2009-02-26T20:44:34Z")

</div>

Brad W. wrote:

> Ruby scripting - I am just starting to learn Ruby and I wanted to know  
> if anyone out there knows it well. I am trying to do a project and I  
> have run into a problem.
> 
> I have an executable file that when run creates (n) number of error  
> logs. So from a command prompt you run the ,exe with with (n) being the  
> number of logs you wish to create. We will make n =10. Then using ruby  
> create a program that will search through those 10 error logs and find  
> and display how many times the word error is found and how many times  
> the word warning is found. Then Produce a report showing the number of  
> error and warning log messages for 10-minute over the entire length of  
> time represented by the generated log files.

Start by reading a good Ruby primer -  
[Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/) is browsable online for  
free, or there are many to choose from any buy. Type in and run the  
examples. Then start writing your own code, and when you get stuck at a  
particular point, you will be able to ask a more specific question.

For example: if you get stuck at iterating over all the files in a  
directory, look at Dir.glob, which is also callable as Dir[]

```
Dir["foo.*"].each do |fn|
  puts fn
end

```

Also, browse the archives of this list. An almost identical question to  
yours (about counting flight arrivals and departures) was asked a day or  
two ago.

Good luck,

Brian.

---

<div class="post-metadata">

**Author:** ![bwinborg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/51bf81/32.png) [@bwinborg](https://www.ruby-forum.com/u/bwinborg)\
**Post date:** [February 26, 2009, 9:06pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477/4 "2009-02-26T21:06:59Z")

</div>

pat eyler wrote:

> On Thu, Feb 26, 2009 at 12:34 PM, Brad W.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > error and warning log messages for 10-minute ï¿½over the entire length of  
> > time represented by the generated log files.
> 
> sounds rather like a homework assignment …
> 
> what have you tried so far?

You are fairly close I am studying ruby and have never programed before  
this is a test I found and wanted to try. I have attached what I have  
and think it should work but I keep getting the following error

Microsoft Windows XP [Version 5.1.2600]  
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Brad\>cd c:\ruby

C:\Ruby\>ruby count.rb  
count.rb:8:in `initialize': No such file or directory - D:\My Documents\My Downl oads\Tezt\files (Errno::ENOENT) from count.rb:8:in `new’  
from count.rb:8

C:\Ruby\>

I have also used the same script with the error file name  
log\_file\_20090221\_095030.txt. I am just using one at this time.

---

<div class="post-metadata">

**Author:** ![bwinborg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/51bf81/32.png) [@bwinborg](https://www.ruby-forum.com/u/bwinborg)\
**Post date:** [February 26, 2009, 9:01pm UTC](https://www.ruby-forum.com/t/ruby-scripting/161477/5 "2009-02-26T21:01:55Z")

</div>

On Thu, Feb 26, 2009 at 2:34 PM, Brad W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am just starting to learn Ruby and I wanted to know  
> if anyone out there knows it well.

Well, there is this one guy in Japan…
