在bash脚本中,我需要等到cpu使用率低于阈值.
换句话说,我需要一个命令wait_until_cpu_low,我将这样使用:
我该怎么办?
编辑:
目标操作系统是:Red Hat Enterprise Linux Server 6.5版
>我正在考虑平均cpu使用率(跨所有内核)
解决方法
- wait_for_cpu_usage()
- {
- current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }')
- while [[ "$current" -ge "$1" ]]; do
- current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }')
- sleep 1
- done
- }
注意它需要安装sysstat包.