Skip to content

Instantly share code, notes, and snippets.

@xraystyle
Created December 20, 2013 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xraystyle/8063335 to your computer and use it in GitHub Desktop.
Save xraystyle/8063335 to your computer and use it in GitHub Desktop.
Quick script to get the total memory usage for a specific user on a server.
#!/usr/bin/env ruby -w
unless ARGV[0]
puts "\nSpecify a username. \n\nUsage:"
puts "usermem UserName\n\n"
exit!
end
total = 0
mem = `ps -u #{ARGV[0]} -o rss`
mem = mem.split("\n")
mem.delete_at(0)
mem.each do |val|
total = total + val.to_i
end
puts "Total memory usage for #{ARGV[0]} in MB: #{total / 1024}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment