The command below is grabing only the first load average, I would like to grab all the 3 load average. How can I change this code?
top -b -n 3 -d 1 | grep "load average" | tail -n 1 | awk '/load average:/ {printf $10}'
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityyou should not use grep | tail | awk
.
top -b -n 1 | awk '/load average/ { printf "%s %s %s\n", $10, $11, $12 }'
have also a look at w
or uptime
or yetis's comment.
as suggested by cas,
number of field might not be the same, depending on OS.
uptime | awk -F' *,? *' '{print $(NF-2), $(NF-1), $NF}'
top -b -n 1 | awk -F' *,? *' '/load average/ { printf "%s %s %s\n", $12, $13, $14 }'
. but using an ncurses program like top
for this is silly. use uptime
or /proc/loadavg
instead. uptime | awk -F' *,? *' '{print $11, $12, $13 }'
/proc/loadavg
" may be the easy answer. Isolate the 3 values withawk '{ print $1,$2,$3 }' /proc/loadavg
,cut -d' ' -f-3 /proc/loadavg
or other unixish other text tools... or is it essential to get them fromtop
?