小编lin*_*bie的帖子

if语句中的两个条件

我在 if 语句中遇到困难

我希望每当内存使用率或 CPU 使用率超过 70% 时就会弹出“系统利用率很高”的消息,现在我在 if 语句中尝试了以下 2 个条件,但它给了我错误。

# This script monitors CPU and memory usage
RED='\033[0;31m'
NC='\033[0m' # No Color


while :
do
  # Get the current usage of CPU and memory

  limit=70.0
  cpuUsage=$(top -bn1 | awk '/Cpu/ { print $2}')
  memTotal=$(free -m | awk '/Mem/{print $2}')
  memUsage=$(free -m | awk '/Mem/{print $3}')
  memUsage=$(( (memUsage * 100) / memTotal ))

  # Print the usage
  echo "CPU Usage: $cpuUsage%"
  echo "Memory Usage: $memUsage%"
  # Sleep for …
Run Code Online (Sandbox Code Playgroud)

command-line bash cpu ram

3
推荐指数
1
解决办法
869
查看次数

标签 统计

bash ×1

command-line ×1

cpu ×1

ram ×1