自动杀掉占用较多CPU资源的Shell脚本

本站所有内容来自互联网收集,仅供学习和交流,请勿用于商业用途。如有侵权、不妥之处,请第一时间联系我们删除!Q群:迪思分享

免费资源网 – https://freexyz.cn/

复制代码

代码如下:

#!/bin/bash

# March-13-2006

# CPUuse trigger script by Noel

#

# bash code to watch a running programs CPU usage.

# if its 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

免费资源网 – https://freexyz.cn/


© 版权声明
THE END
★喜欢这篇文章吗?喜欢的话,麻烦动动手指支持一下!★
点赞13 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容