As I’m slowly writing my logging script, I’ve hit sort of a snag. I’ve gotten the bulk of the program to work, but now I’m just adding in some creature comforts, such as some limits on what you can enter and whatnot.
def HitsPerMinute()
print "Is there a specific hour you would like to see: "
STDOUT.flush
mhour = spectime = gets.strip
#mhour = mhour.to_s
if mhour == '' or mhour == '\n' or (mhour =~ /[a-z]|[A-Z].*/)
puts "Please enter an hour you would like to see."
HitsPerMinute()
#else
#mhour = mhour.to_i
end
mstart = 00
mend = 59
mstart.upto(mend) { |x|
moment = "#{rightnow}:#{zeroadder(mhour)}:#{zeroadder(x)}".strip
print "Server hits at '#{moment}: "
puts `cat /home/*/var/*/logs/transfer.log | grep -c #{moment}`
x = x.to_i
x = x.next
}
end
HitsPerMinute()
For the most part it works fine and well, except it seems to store the variables that are entered before. As shown here.
Is there a specific hour you would like to see:
Please enter an hour you would like to see.
Is there a specific hour you would like to see:
Please enter an hour you would like to see.
Is there a specific hour you would like to see: d
Please enter an hour you would like to see.
Is there a specific hour you would like to see: 13
Server hits at '10/Oct/2012:13:00: 48
[...]
Server hits at '10/Oct/2012:13:59: 187
Server hits at '10/Oct/2012:0d:00: 0
Server hits at '10/Oct/2012:0d:01: 0
[...]
Server hits at '10/Oct/2012:0d:57: 0
Server hits at '10/Oct/2012:0d:58: 0
Server hits at '10/Oct/2012:0d:59: 0
Server hits at '10/Oct/2012::00: 0
Server hits at '10/Oct/2012::01: 0
[...]
I use .strip on my input variables, but that doesn’t seem to do anything for this issue. I tried using .flush but that doesn’t seem to do much either. How is it even storing multiple variables?
the HitsPerMinute method is called several times, when the if condition ends it continues the run, do it in a loop instead
it is not storing several values on mhour variable, mhour has only one value each time the method is called. User is answered to enter a new value before the method reaches its end, so when it finally ends, the previous calls continue its run, maybe this example helps to understand:
output: