天际说

bash script for killing process which abuse SSH system

发布时间:2013年3月30日 / 分类:运维经验 / 6,353 次围观 / 抢沙发!

#! /bin/bash
# control ssh tunnel process script, running on centos 5/6
# ssh process greater than 20 will be killed automatically, use crontab running every 15 minutes
# by @twfcc public domain, $PROG:2much_process   
list="/var/mail"
max_process=20
for i in $(ls "$list") ; do
    count=$(ps aux | grep -i "$i" | grep -v grep | awk '{print $2}')
    if [ -z "$count" ] ; then
       continue
    fi

    process=($(echo "$count"))
    how_many=${#process[@]}
    if [ $how_many -gt $max_process ] ; then
       kill $(ps aux | grep -i "$i" | grep -v grep | awk '{print $2}')
    fi
done
exit 0

标签:none