I need to monitor CPU usage by users of two servers' (Ubuntu and CentOS). For example:user1     5%user2    10%...Is there a tool similar to top or htop that can do that?
How can I monitor CPU usage by user?
ubuntu;centos;cpu
Here is a script to print the total CPU usage for each user currently logged in, showPerUserCPU.sh:own=$(id -nu)for user in $(who | awk '{print $1}' | sort -u)do    # print other user's CPU usage in parallel but skip own one because    # spawning many processes will increase our CPU usage significantly    if [ $user = $own ]; then continue; fi    (top -b -n 1 -u $user | awk -v user=$user 'NR>7 { sum += $9; } END { print user, sum; }') &donewait# print own CPU usage after all spawned processes completedtop -b -n 1 -u $own | awk -v user=$own 'NR>7 { sum += $9; } END { print user, sum; }'And here is a slightly modified version for printing the CPU usage of all available users (but skipping the ones with a CPU usage of zero), showAllPerUserCPU.sh:own=$(id -nu)for user in $(getent passwd | awk -F : '{print $1}' | sort -u)do    # print other user's CPU usage in parallel but skip own one because    # spawning many processes will increase our CPU usage significantly    if [ $user = $own ]; then continue; fi    (top -b -n 1 -u $user | awk -v user=$user 'NR>7 { sum += $9; } END { if (sum > 0.0) print user, sum; }') &donewait# print own CPU usage after all spawned processes completedtop -b -n 1 -u $own | awk -v user=$own 'NR>7 { sum += $9; } END { print user, sum; }'There is also a related script for showing the total memory usage for each user: showPerUserMem.shFor live-monitoring just execute these scripts periodically via the watch command.