I want to do some analysis of the Redmine log files, including the previous log. So I want to catenate logfile.log.0 and logfile.log, and loop through the output one line at a time. I wrote the following code:
module MyModule
def analyze_log
logfile = '/www/redmine/log/logfile.log'
cat_cmd = "cat #{logfile}.0 #{logfile}"
cat = IO.popen(cat_cmd)
cat.readlines do |line|
puts line
end
end
end
The code (without the module and method definition) works perfectly when I do it in irb, but on the same machine it does not work (does not print the lines) when I wrap the code in a method (analyze_log) in a module (MyModule), and call that from a script, as follows:
#!/opt/ruby/bin/ruby
require './my_module'
include MyModule
analyze_log
What gives?
BTW, if there is a better way to process multiple files sequentially in the same loop, I'd be happy to hear about it. But my main concern is that it works in irb but not when run as a script.
I AM running the script as the same user for which I ran irb.