From 68bb4f15e2514f470acc989eccf1fe44700d018f Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 24 Oct 2022 22:45:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dshell=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=A3=81=E7=9B=98=E4=BD=BF=E7=94=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/otask.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shell/otask.sh b/shell/otask.sh index 89e900f9..4cbf4eb8 100644 --- a/shell/otask.sh +++ b/shell/otask.sh @@ -75,13 +75,13 @@ run_nohup() { } check_server() { - cpu_use=$(top -b -n 1 | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%") + cpu_use=$(top -b -n 1 | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%" | head -n 1) - mem_free=$(free -m | grep "Mem" | awk '{print $3}') - mem_total=$(free -m | grep "Mem" | awk '{print $2}') - mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%") + mem_free=$(free -m | grep "Mem" | awk '{print $3}' | head -n 1) + mem_total=$(free -m | grep "Mem" | awk '{print $2}' | head -n 1) + mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%" | head -n 1) - disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%") + disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%" | head -n 1) if [[ $cpu_use -gt $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then local resource=$(top -b -n 1 | grep -v -E 'grep|Mem|idle|Load' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10)