Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created May 30, 2010 03:24
Show Gist options
  • Save codebutler/418747 to your computer and use it in GitHub Desktop.
Save codebutler/418747 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# XXX: Don't hardcode these paths!
require '/usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/number_helper.rb'
require '/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/core_ext/numeric/bytes.rb'
include ActiveSupport::CoreExtensions::Numeric::Bytes
include ActionView::Helpers::NumberHelper
BLOCKSIZE = 1024
def get_quota_info
username = `whoami`.chomp
quota_info = `/usr/sbin/quotatool -d -u #{username} /`.split(' ' )
current = quota_info[2].to_i
quota = quota_info[3].to_i
limit = quota_info[4].to_i
free = (limit - current) * BLOCKSIZE;
result = {}
result[:used] = number_to_human_size(current * BLOCKSIZE)
if limit > 0
result[:free] = number_to_human_size(free)
result[:limit] = number_to_human_size(limit * BLOCKSIZE)
end
result
end
quota_info = get_quota_info()
free = quota_info[:free]
used = quota_info[:used]
limit = quota_info[:limit]
puts ""
if quota_info.include?(:free)
puts "You have used #{used} of #{limit}. #{free} remaining."
else
puts "You have used #{used}."
end
puts ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment