前提是需要获取非法登录用户的IP,并作为参数传给脚本
#!/bin/bash
if [ -z $1 ]
then
echo "`basename $0` enter error!"
fi
host_name=`who | grep "$1" | awk '{print $2}'`
pid=`ps aux | grep "$host_name" | grep "bash" | awk '{print $2}'`
echo $pid | tee pid
sed 's/ /\n/gw pid_file' pid
while read LINE
do
kill -9 $LINE
done < pid_file
#count=`awk '{print NF}' pid`
#echo $count
#kill -9 $pid
本文介绍了一种通过Shell脚本自动化终止特定非法登录用户进程的方法。该脚本首先检查是否提供了用户IP作为参数,然后查找对应主机名,进一步获取并终止与该主机名相关的bash进程。
6330

被折叠的 条评论
为什么被折叠?



