2

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}'
1
  • 2
    "Have a look at /proc/loadavg" may be the easy answer. Isolate the 3 values with awk '{ 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 from top? – user62916 Oct 31 '15 at 13:28
3

you 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}'
3
  • nice really nice command! The output is something like this "0.10, 0.34, 0.39" would it be possible to output "0.10 0.34 0.39" without commas? – Samul Oct 31 '15 at 13:44
  • 1
    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 }' – cas Nov 1 '15 at 0:21
  • @archemar - my version of top (procps-ng version 3.3.10 on debian sid) had loadavg in fields $12-$14 instead of $10-$12. – cas Nov 1 '15 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.