特别感谢作者:kpjiang兄
可以先建立一个deny.user的文件,内容如下:
user1
user2
user3
然后将下列代码加到 /etc/porfile里
logname=`whoami |grep '{print $1}'`
while read i; do
if [ $i =$logname ]; then
echo "Sorry,$LOGNAME can not login" && exit
fi
do < /path/deny.user
自己写三个shell程序,调用at和系统维护功能:
1. 在指定的时间执行该shell,在/etc下生成一名为nologin的文件,如:
vi /sbin/login.denied
echo " Login Denied " > /etc/nologin
chmod 700 login.denied
2. 在指定的时间执行该shell,删除/etc/下的nologin文件,如:
vi /sbin/login.allowed
if [ -f /etc/nologin ]; then
rm /etc/nologin
fi
chmod 700 login.allowed
3. 编写一个限制时间的shell,如:
vi /sbin/security
if [ -f /sbin/login.denied ]; then
at -f /sbin/login.denid 22:00
fi
if [ -f /sbin/login.allowed ]; then
at -f /sbin/login.allowed 8:00
if
#!/bin/sh
# The right of usage, distribution and modification is here by granted by the author.
# The author deny any responsibilities and liabilities related to the code.
#
OK=0
A=`find $1 -print`
if expr $3 == 1 >/dev/null ; then M=Jan ; OK=1 ; fi
if expr $3 == 2 >/dev/null ; then M=Feb ; OK=1 ; fi
if expr $3 == 3 >/dev/null ; then M=Mar ; OK=1 ; fi
if expr $3 == 4 >/dev/null ; then M=Apr ; OK=1 ; fi
if expr $3 == 5 >/dev/null ; then M=May ; OK=1 ; fi
if expr $3 == 6 >/dev/null ; then M=Jun ; OK=1 ; fi
if expr $3 == 7 >/dev/null ; then M=Jul ; OK=1 ; fi
if expr $3 == 8 >/dev/null ; then M=Aug ; OK=1 ; fi
if expr $3 == 9 >/dev/null ; then M=Sep ; OK=1 ; fi
if expr $3 == 10 >/dev/null ; then M=Oct ; OK=1 ; fi
if expr $3 == 11 >/dev/null ; then M=Nov ; OK=1 ; fi
if expr $3 == 12 >/dev/null ; then M=Dec ; OK=1 ; fi
if expr $3 == 1 >/dev/null ; then M=Jan ; OK=1 ; fi
if expr $OK == 1 > /dev/null ; then
ls -l --full-time $A 2>/dev/null | grep "$M $4" | grep $2 ;
else
echo Usage: $0 path Year Month Day;
echo Example: $0 ~ 1998 6 30;
fi