网上查了很多,没有效果,自己写了一个,虽然有点次,但是功能还是能实现了.废话少说,看shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
 
function main 
{ 
	lines=`ps -eo user,pid,cmd | grep -v root |grep sshd`;
	tmp=0;
	array=();
	for i in ${lines[*]}
	do			
		if [ $(($tmp%4)) -eq 0 -o $(($tmp%4)) -eq 1 ]
		then						
			array=(${array[@]} $i);		
		fi		
		tmp=$(($tmp+1));
	done
 
	for i in ${array[*]}
	do
		tmp=0;
		for((j=0;j< ${#array[*]};++j))
		do
			p=${array[$j]};
			if [ "$i" == "$p" ]
			then
				tmp=$(($tmp+1));
			fi
			if [ $tmp -eq 2 ]
			then
				p=${array[$(($j+1))]};
				kstr=`kill -9 $p`;
				echo $kstr;
				break;
			fi
 
		done
	done
 
}
while [ 2 -ge 1 ]
do
	main;
	sleep 2;
done