手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >自动杀掉占用较多CPU资源的Shell脚本
自动杀掉占用较多CPU资源的Shell脚本
摘要:复制代码代码如下:#!/bin/bash#March-13-2006#CPUusetriggerscriptbyNoel##bashcode...

复制代码 代码如下:

#!/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

【自动杀掉占用较多CPU资源的Shell脚本】相关文章:

Linux下实现SNMP一键安装的Shell脚本

控制输出颜色的shell脚本

linux下mysql如何自动备份shell脚本

检测网段IP使用情况的shell脚本

备份shell脚本实例代码

5个实用的shell脚本面试题和答案

用expect实现的自动登录到多台服务器的shell脚本

一个简洁的全自动安装LNMP服务器环境的Shell脚本分享

linux下自动备份MySQL数据并上传到FTP上的shell脚本

自动重启服务的shell脚本代码

精品推荐
分类导航