自動殺掉占用較多CPU資源的Shell腳本
#!/bin/bash
# March-13-2006
# CPUuse trigger script by Noel
#
# bash code to watch a running program's CPU usage.
# if it's above a set value, it will auto send an email.
# You will need to set a Cron job to run this script every xx minutes
#
# Set some needed things:
#
processToWatch="convert" # in my case I need to watch convert
emailAddress="root@host" # this is my main emailaddress
triggerValue=90 # if the CPU use is above 90% send an email. DO NOT USE a DOT or COMMA!
tempFileName=tmp-cpu # some name of the temp file for the ps, grep data
ps auxww | grep "$processToWatch" | grep -v grep > /tmp/$tempFileName
export LINE
(
read LINE
while [ -n "$LINE" ]
do
set $LINE
read LINE
if [ $(echo "$3" | sed -e 's/\.[0-9]*//g') -gt $triggerValue ]; then
mail -s "CPU message alert for: $processToWatch" $emailAddress <<-END
This is to inform you that the following process: $processToWatch with PID (Process ID) $2 is now using more than your preset $triggerValue value.
Process: $processToWatch is using: $3 of CPU power!
The command used is: $11
END
fi
done
)< /tmp/$tempFileName
相關(guān)文章
shell腳本實現(xiàn)磁盤監(jiān)控系統(tǒng)
這篇文章主要介紹了shell腳本實現(xiàn)磁盤監(jiān)控系統(tǒng),幫助大家更好的利用shell腳本管理數(shù)據(jù),感興趣的朋友可以了解下2020-09-09
linux 比較兩個文件夾diff不同 (diff命令, md5列表)
這篇文章主要介紹了linux 比較兩個文件夾diff不同 (diff命令, md5列表),比較文件夾diff,可以直接使用diff命令,也可以比較文件md5列表,下面通過實例給大家介紹下,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05
Shell腳本調(diào)試?-n?-v?-x?-c的具體用法
本文主要介紹了Shell腳本調(diào)試?-n?-v?-x?-c的具體用法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06
CentOS 6.0 啟動時出現(xiàn)fstab錯誤時的修復(fù)方法
下面小編就為大家?guī)硪黄狢entOS 6.0 啟動時出現(xiàn)fstab錯誤時的修復(fù)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03
linux BASH shell下設(shè)置字體及背景顏色
這篇文章主要介紹了linux BASH shell下設(shè)置字體及背景顏色的方法,需要的朋友可以參考下2014-04-04

