#!/bin/bash
stats=""
echo "% user"
echo "============"
# get all users from linux
for user in `ps aux | grep -v COMMAND | awk '{print $1}' | sort -u`
# find the memory usage % for each user
do
stats="$stats\n`ps aux | egrep ^$user | awk 'BEGIN{total=0}; \
{total += $4};END{print total,$1}'`"
done
# sort data numerically (largest first)
echo -e $stats | grep -v ^$ | sort -rn | head