Shell脚本获取linux系统用户的内存使用情况

  • Post author:
  • Post category:linux




Shell脚本获取linux系统用户的内存使用情况



#!/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



版权声明:本文为jakkiejinn原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。