自动杀掉占用较多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 dataps 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
Linux中获取某个进程的系统调用以及参数(故障排查案例)
当一个程序发生故障时,有时候想通过了解该进程正在执行的系统调用来排查问题。通常可以用strace来跟踪。但是当进程已经处于D状态(uninterruptibleslee
在Shell中分割字符串的例子
比如,要分割test=aaa,bbb,cccc,dddd,可以这样arr=$(echo$test|tr",""n")还可以这样OLD_IFS=$IFSIFS=','arr=$testIFS=$OLD_IFS然后用forxin$arr;doecho$xdone看看效果或者更直接一
一个Linux系统安全设置的Shell脚本的分享(适用CentOS)
我们将常用的系统安全配置制作为一个shell脚本,只需要在服务器上运行这个shell脚本即可完成安全设置。linux的系统安全设置Shell脚本是第二次更新,已
编辑:一起学习网
标签:脚本,系统安全,进程,中分,故障