主页 > 知识库 > 自动杀掉占用较多CPU资源的Shell脚本

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

热门标签:百度竞价排名 网站排名优化 地方门户网站 服务外包 铁路电话系统 AI电销 呼叫中心市场需求 Linux服务器

复制代码 代码如下:

#!/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脚本
  • 统计 cpu 内存 使用率的shell脚本代码
  • 消耗CPU资源的shell脚本
  • 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
  • Linux中使用Shell脚本查看Java线程的CPU使用情况
  • Shell脚本实现把进程负载均衡到多核CPU中
  • shell脚本监控系统负载、CPU和内存使用情况
  • Linux shell脚本实现CPU预警

标签:崇左 黄山 湖南 铜川 兰州 湘潭 仙桃 衡水

巨人网络通讯声明:本文标题《自动杀掉占用较多CPU资源的Shell脚本》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266