9/26/2008

Disk Checker Ruby Program

I wrote ruby program to work checking disk and reporting result.

It is following code


#!/usr/bin/ruby
require 'net/smtp'

if ARGV[0] == nil then
print "usage : " + $0 + " directory\n"
exit(1)
end

print "check directory " + ARGV[0] + "\n"

cmd = "du -h -c " + ARGV[0]

array = []

IO.popen(cmd, 'r+') do |pipe|
t = pipe.read
t.gsub(/(?:[0-9]+(\.[0-9]*)?|(\.[0-9]+))([eE][-+]?[0-9]+)?\w/){|s|
array.push(s)
}
end

mailstring = "total = " + array.last() + "\n"

Net::SMTP.start( 'severname', portnumber ) {|smtp|
smtp.send_mail(mailstring, "from@localhost", "to@localhost")
}

No comments: