您的位置:首页 > 运维架构 > Shell

shell脚本示例,运行无限循环的shell脚本来检测拒绝列表上的用户是否登录到UNIX系统多于一次。

2018-02-26 14:54 976 查看
#! /bin/sh

while true
do
who | cut -d " " -f1 | sort> old.txt
sleep 3
who | cut -d " " -f1 | sort> new.txt

comm old.txt new.txt -2 -3 >> logOneTime.txt
comm old.txt new.txt -1 -3 > newLog.txt

num=0
cat newLog.txt | while read line
do
if grep $line['-'] user.deny>/dev/null
then
if grep $line logOneTime.txt>/dev/null
then
fullName=`grep $line['-'] user.deny | cut -d "-" -f2`
num=`expr $num + 1`
echo -e "The user $fullName (on the denial list) has logged in more than once!\n"
fi
fi
done

if [ $num -eq 0 ]
then
echo -e "No user on the user.deny list has multiple logins\n"
fi
done

while true
do
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: