我在 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)