您现在的位置是:网站首页> 编程资料编程资料
自动杀掉占用较多CPU资源的Shell脚本_linux shell_
2023-05-26
354人已围观
简介 自动杀掉占用较多CPU资源的Shell脚本_linux 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
相关内容
- Shell脚本获取进程的运行时间_linux shell_
- Shell中的循环语句for、while、until实例讲解_linux shell_
- Shell脚本处理浮点数的运算和比较实例_linux shell_
- Linux中删除文件内空行的4种方法_linux shell_
- Shell处理带空格的文件名的方法_linux shell_
- Linux中使用Shell脚本查看Java线程的CPU使用情况_linux shell_
- a10 config backup for aXAPI_linux shell_
- linux系统中的列出敏感用户的脚本代码_linux shell_
- shell脚本中执行python脚本并接收其返回值的例子_linux shell_
- shell脚本实现拷贝大文件显示百分比的代码分享_linux shell_
