Skip to content

Instantly share code, notes, and snippets.

@trueheart78
Last active August 29, 2015 14:08
Show Gist options
  • Save trueheart78/a61c35018ebe467b4685 to your computer and use it in GitHub Desktop.
Save trueheart78/a61c35018ebe467b4685 to your computer and use it in GitHub Desktop.
A simple ruby script to monitor filesizes during a large transfer. Setup to run through cron. Requires the mandrill-api gem to be installed, as well as a mandrill API key in your enviroment in MANDRILL_APIKEY
require 'mandrill'
files = ["mh-files-wo-lb-20141026_0009.tar.gz","mh-files-lb-only-20141026_0009.tar.gz"]
files.each do |f|
if File.exist?(f)
size = File.stat(f).size
gb = 1024 ** 3
mb = 1024 ** 2
status = "#{size / gb} gb (#{size / mb} mb)"
puts "File #{f} - as of #{Time.now}:\n"
puts "#{status}\n"
m = Mandrill::API.new
message = {
:subject=> "Status: #{status} [#{f}]",
:from_name=> "Your Friendly Neighborhood Server",
:text=>"See?",
:to=>[
{
:email=> "bill@example.com",
:name=> "Billy"
}
],
:html=>"#{status} for #{f}",
:from_email=>"bobby@example.com"
}
sending = m.messages.send message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment