Bash – How to divide the output of one command by the output of another

bashman

I would like to know the server load divided by the amount of CPU cores in order to judge which servers are overloaded. I can get the amount of CPU cores with:

$ grep -c processor /proc/cpuinfo
2

I can get the server load with:

$ uptime | awk '{print $11}'
0.47,

Now I would like to divide 0.47/2 to get 0.23. How would I know which manpage to read to do this? I'm really looking for how I can learn what the next step in finding the correct command is, I'm not asking for the command itself.

I've tried searching the question online and even Google couldn't steer me in the right direction. Thus, alternatively, which keywords should I be searching on? The obvious "linux, division, bash, output" did not help.

Best Answer

This should do the trick:

(awk '{printf "%s/", $2}' /proc/loadavg; grep -c processor /proc/cpuinfo;) | bc -l

Also, you should get the load from /proc/loadavg where the command uptime also gets it.

Related Question