Linux用户使用telnet登录失败三次不能使用
目的:练习awk的使用
功能:Linux帐号使用telnet错误登录三次,成功登录后会退出系统(本想实现不能登录,水平不够未能实现)
将下面的代码加入到/etc/profile中
loguser=$LOGNAME
day=`date +%e | sed 's/[ ]*//g'`
month=`date +%b`
count=0
logtime=`lastb |grep $loguser | awk '{if($5=="'$month'" && $6=="'$day'") count++}END{print count}'`
if [ "$logtime" != "" ]
then
if [ $logtime -gt 3 ]
then
echo "You have failed login more than three times,please login tomrrow or you can connect to admin!"
sleep 5
exit 0
fi
fi
day=`date +%e | sed 's/[ ]*//g'`
month=`date +%b`
count=0
logtime=`lastb |grep $loguser | awk '{if($5=="'$month'" && $6=="'$day'") count++}END{print count}'`
if [ "$logtime" != "" ]
then
if [ $logtime -gt 3 ]
then
echo "You have failed login more than three times,please login tomrrow or you can connect to admin!"
sleep 5
exit 0
fi
fi
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7419833/viewspace-566649/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7419833/viewspace-566649/