自動(dòng)殺掉占用較多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
- 一個(gè)用了統(tǒng)計(jì)CPU 內(nèi)存 硬盤 使用率的shell腳本
- 統(tǒng)計(jì) cpu 內(nèi)存 使用率的shell腳本代碼
- 消耗CPU資源的shell腳本
- 使用shell腳本采集系統(tǒng)cpu、內(nèi)存、磁盤、網(wǎng)絡(luò)等信息
- Linux中使用Shell腳本查看Java線程的CPU使用情況
- Shell腳本實(shí)現(xiàn)把進(jìn)程負(fù)載均衡到多核CPU中
- shell腳本監(jiān)控系統(tǒng)負(fù)載、CPU和內(nèi)存使用情況
- Linux shell腳本實(shí)現(xiàn)CPU預(yù)警
相關(guān)文章
shell腳本實(shí)現(xiàn)磁盤監(jiān)控系統(tǒng)
這篇文章主要介紹了shell腳本實(shí)現(xiàn)磁盤監(jiān)控系統(tǒng),幫助大家更好的利用shell腳本管理數(shù)據(jù),感興趣的朋友可以了解下2020-09-09linux 比較兩個(gè)文件夾diff不同 (diff命令, md5列表)
這篇文章主要介紹了linux 比較兩個(gè)文件夾diff不同 (diff命令, md5列表),比較文件夾diff,可以直接使用diff命令,也可以比較文件md5列表,下面通過實(shí)例給大家介紹下,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05shell之定時(shí)周期性執(zhí)行腳本的方法示例
這篇文章主要介紹了shell之定時(shí)周期性執(zhí)行腳本的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10Shell腳本調(diào)試?-n?-v?-x?-c的具體用法
本文主要介紹了Shell腳本調(diào)試?-n?-v?-x?-c的具體用法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06CentOS 6.0 啟動(dòng)時(shí)出現(xiàn)fstab錯(cuò)誤時(shí)的修復(fù)方法
下面小編就為大家?guī)硪黄狢entOS 6.0 啟動(dòng)時(shí)出現(xiàn)fstab錯(cuò)誤時(shí)的修復(fù)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03shell腳本使用兩個(gè)橫杠接收外部參數(shù)的方法
這篇文章主要介紹了shell腳本使用兩個(gè)橫杠接收外部參數(shù)的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12linux BASH shell下設(shè)置字體及背景顏色
這篇文章主要介紹了linux BASH shell下設(shè)置字體及背景顏色的方法,需要的朋友可以參考下2014-04-04