Memory Usage: 33/512MB (6%)
disk usage: 4.2/20GB (23%)
cpu Load: 0.01
所以我开始使用下面的脚本来做到这一点,但是以某种方式它给了我一个错误
#!/bin/bash
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "cpu Load: %.2f\n", $(NF-2)}'
以下是我得到的错误-
awk: run time error: not enough arguments passed to printf("Memory Usage: %s/%sMB (%.2f%)
")
FILENAME="-" FNR=2 NR=2
我正在运行ubuntu 12.04.知道有什么问题吗?
更新:-
运行下面的shell脚本后-
#!/bin/bash
free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "cpu Load: %.2f\n", $(NF-2)}'
我低于输出-
Memory Usage: 128504/128896MB (99.70%)
disk Usage: 3/48GB (8%)
cpu Load: 0.40
cpu负载看起来还可以吗? 0.40是什么意思?我应该说多少个数字会增加cpu负载?
解决方法:
尝试转义%:
printf "Memory Usage: %s/%sMB (%.2f%%)\n"