ps_moniter.sh #!/bin/bash . /etc/profile let LIMIT_PROCESS=400 let LIMIT_BIG_PROCESS=40 ALL_PROCESS_NUM=`ps x |wc -l` if [ ${ALL_PROCESS_NUM} -gt ${LIMIT_PROCESS} ]; then echo ${ALL_PROCESS_NUM} fi BIG_PROCESS=`ps x -o cmd |sort |uniq -c |sort -n |tail -n 10` BIG_PROC_SUM=`echo "${BIG_PROCESS}" |awk ' { SUM=SUM+$1 } END { print SUM } '` if [ ${BIG_PROC_SUM} -gt ${LIMIT_BIG_PROCESS} ]; then MESSAGE="Process Report [Big Process Larger than ${LIMIT_BIG_PROCESS}] ${BIG_PROCESS}" echo "$MESSAGE" fi crontab */5 * * * * cd /root/bin && ./ps_moniter.sh &>/dev/null