Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make Linux shell script realize CPU early warning

Shulou Source: shulou.com Published: 2022-06-03 09:22:10 11月15日 Update

This article introduces the relevant knowledge of "how to make Linux shell scripts achieve CPU early warning". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

#! / bin/bash#cpu idle percentcpu_idle= `top-b-d 1-n 2 | grep Cpu | awk'NR > 1 {print $5}'| cut-f 1-d "." `if [- d "/ opt/scripts/log"] then cd / opt/scriptselse mkdir / opt/scripts/logfi count=0condition=truewhile conditiondo if [$cpu_idle-le 20] then pids= `top-b-d 1-n 1 | grep java | awk'{if ($9 > 80) print $1} '`for (a = 1; a;

< 10; a++)) do for pid in $pids doi #involve jdk existence check later date=`date +%Y%m%d%H%M` sh showstack.sh -c 30 -p $pid >

Log/stack_$pid_$date.log jstat-gcutil $pid > log/gc_$pid_$date.log done done for pid in $pids do date= `date +% Y% m% d% H% M`jmap-heap $pid > log/heap_$pid_$date.log done count++ cpu_idle= `top-b-d 1-n 2 | grep Cpu | awk'NR > 1 {print $5}'| cut-f 1-d "." `if [$count-ge 3] then # send emaili # server ip address ip= `ifconfig eth0 | grep "inet addr" | cut-f 2-d ":" | cut-f 1-d "`condition=false count=0 fi else condition=false count=0 fidone" how to make Linux shell scripts achieve CPU early warning "this is the end of the introduction. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Scripts early warning content more knowledge practical successful learning next dilemma reality situation articles cases editing websites industries processes high quality learning related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Redmi Shulou Technology NVidia