I want to display the calculation of the CPU load in percentage.
num2=$(uptime | grep "average:" | tr -d " " | cut -d ':' -f 5 | cut -d ',' -f 2) percent=$((num2(*100))) echo 'CPU percentage' $percent
Am I missing something?
You can pipe your calculation for
percent=$(echo "scale=0;$num2*100" | bc)
It'll give you a number like "41.00" you can cut that off the end with
num2 value will be something like
bash can do integer calculations only, no floating. That's why we get an eror msg like
bash: 0.41 * 100 : syntax error: invalid arithmetic operator (error token is ".41 * 100 ")
Try removing the dots when using your
tr -d statement. That would be equivalent to a multiplication by 100.