自動殺掉占用較多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)文章
淺析使用?Auditbeat?模塊監(jiān)控?shell?命令的問題
Auditbeat Audited 模塊可以用來監(jiān)控所有用戶在系統(tǒng)上執(zhí)行的 shell 命令,在終端用戶偶爾才會登錄的服務(wù)器上,通常需要進行監(jiān)控,本文給大家介紹使用?Auditbeat?模塊監(jiān)控?shell?命令的相關(guān)知識,感興趣的朋友一起看看吧2022-02-02
一個監(jiān)控LINUX目錄和文件變化的Shell腳本分享
這篇文章主要介紹了一個監(jiān)控LINUX目錄和文件變化的Shell腳本分享,對服務(wù)器經(jīng)常被掛馬的朋友時分有用,需要的朋友可以參考下2014-09-09
linux shell實現(xiàn)獲取用戶輸入指定范圍的單個字符的兩種方法
用shell實現(xiàn)的,要求獲取用戶輸一個字符a-zA-Z實現(xiàn)方法如下,需要的朋友可以參考下2013-03-03
linux中編寫自己的并發(fā)隊列類(Queue 并發(fā)阻塞隊列)
這篇文章主要介紹了linux中編寫并發(fā)隊列類,功能有:并發(fā)阻塞隊列、有超時限制、有大小限制2013-12-12
Linux更新Python版本及修改python默認版本的方法
很多情況下拿到的服務(wù)器python版本很低,需要自己動手更改默認python版本,但是有好多朋友都被這個問題難倒了,接下來,通過本篇文章給大家介紹linux更新Python版本及修改默認版本的方法,感興趣的朋友一起學習吧2015-12-12

