L
Lovell Mcilwain
Hello all, (yes its me again
)
I'm here at work and was hit with a very interesting problem. My boss
would like for me to build a script that monitors disk usage on our
database systems (OS X).
I figured what better way to learn ruby then go right into a live
situation. Granted, I'm not sure I'm ready for it but hell I will give
it a shot anyway.
So I don't have a specific way to implement this so I figure I try
something that I believe to be basic.
1. Generate a file (df -k > filename.txt)
2. Read the file using Ruby code
A. compare bites or percentage size (which ever is easier) with a set
size that I determine. If the size read in exceeds the size that I have
determined then it shoots a warning to me via e mail letting me know I
need to deal with it.
So, now that I have my idea out of my head an on paper, I started
writing my code.
require 'yaml' # Just in case I need it
doc_array = [] # Array to have each line read from the file put into a
list
file = File.new('diskcheck.txt','r') # Read the file
while(line = file.gets) # Condition to put the files into the array
doc_array[doc_array.length] = line
end
puts doc_array # Test to see if file was read into array correctly
So on to my problem (thanks for reading this far),
When I try to get an ouput of the array that is supposed to have the
several lines of the file read, it actually doesn't come up with
anything.
I run my program and it just exits without any errors but there is also
no output that comes to the screen... Do I need to convert this file or
find a better way to read in this file?
When I read in this file, It doesn't spit out anything
I'm here at work and was hit with a very interesting problem. My boss
would like for me to build a script that monitors disk usage on our
database systems (OS X).
I figured what better way to learn ruby then go right into a live
situation. Granted, I'm not sure I'm ready for it but hell I will give
it a shot anyway.
So I don't have a specific way to implement this so I figure I try
something that I believe to be basic.
1. Generate a file (df -k > filename.txt)
2. Read the file using Ruby code
A. compare bites or percentage size (which ever is easier) with a set
size that I determine. If the size read in exceeds the size that I have
determined then it shoots a warning to me via e mail letting me know I
need to deal with it.
So, now that I have my idea out of my head an on paper, I started
writing my code.
require 'yaml' # Just in case I need it
doc_array = [] # Array to have each line read from the file put into a
list
file = File.new('diskcheck.txt','r') # Read the file
while(line = file.gets) # Condition to put the files into the array
doc_array[doc_array.length] = line
end
puts doc_array # Test to see if file was read into array correctly
So on to my problem (thanks for reading this far),
When I try to get an ouput of the array that is supposed to have the
several lines of the file read, it actually doesn't come up with
anything.
I run my program and it just exits without any errors but there is also
no output that comes to the screen... Do I need to convert this file or
find a better way to read in this file?
When I read in this file, It doesn't spit out anything