- 论坛徽章:
- 0
|
回复 2# Looiml
感谢你:)
代码可以使用,做一个crontab每个3秒执行一次还是蛮好用的,我手工测试结果如下:
root@ubuntu:~# ps -eo user,pid,etime,cmd | grep sshd
root 4195 05:07:30 /usr/sbin/sshd -D
root 4479 05:07:20 sshd: root@pts/5,pts/4
root 5850 05:41 sshd: user6 [priv]
user6 6006 05:41 sshd: user6
root 6873 04:13 sshd: user6 [priv]
user6 7007 04:12 sshd: user6
root 7023 01:05 sshd: user5 [priv]
user5 7157 01:05 sshd: user5
root 7293 00:48 sshd: user5 [priv]
user5 7427 00:47 sshd: user5
root 7434 00:00 grep --color=auto sshd
root@ubuntu:~# ps -eo user,pid,cmd|grep -P '^(?!root).*sshd'|awk 'a[$1]++{print $2}'|xargs -n1 kill -9
root@ubuntu:~# ps -eo user,pid,etime,cmd | grep sshd
root 4195 05:07:43 /usr/sbin/sshd -D
root 4479 05:07:33 sshd: root@pts/5,pts/4
root 5850 05:54 sshd: user6 [priv]
user6 6006 05:54 sshd: user6
root 7023 01:18 sshd: user5 [priv]
user5 7157 01:18 sshd: user5
root 7442 00:00 grep --color=auto sshd
|
|