Idle time logout mechanism (daemon)
Bob Peirce
rbp at investor.UUCP
Thu Jul 18 03:44:57 AEST 1985
> Does anyone have (or know of) a daemon which will monitor users idle time,
> and logout any user idle longer than a given amount of time.
> Please respond via mail and as usual, I will summarize for the net.
Sorry, I don't have a path to you, but this works on SYS III. I use
it as part of my el-cheapo, one modem both ways set-up. Stick it in
cron to run every once in a while. You may want to modify this to
handle several lines.
# -- ckmod
# Robert B. Peirce; Cookson, Peirce & Co., Inc.
# If anyone is inactive on a modem > $GRACE minutes log them off
# This version gives no quarter.
# Have to look for hung outgoing uucp stuff too.
if [ $# -ne 1 ]
then
echo "usage: ckmod tty#"
exit 1
fi
MODEM=$1
GRACE=15 # minutes of no activity
HM=/usr/lib/uucp
LOG=/u/rbp/kill.log
SPOOL=/usr/spool/uucp
cd $HM
# If set doesn't produce anything, force it.
set `who | grep tty$MODEM || echo XXX`
U=$1
if [ $U = XXX ]
then
U=""
fi
# Get current time
set `date | tr ":" " "`
M=$2
D=$3
HC=$4
MC=$5
# Get time device last accessed
set `/usr/ucb/ls -l /dev/tty$MODEM | tr ":" " "`
HL=$8
ML=$9
# Check for midnight crossover
if [ $HL -gt $HC ]
then
HL=`expr $HL + 24`
fi
# Calculate time since last access of device
TIME=`expr \( 60 "*" $HC + $MC \) - \( 60 "*" $HL + $ML \)`
if [ $U ]
then
if [ $TIME -ge 1 ]
then
echo "$U tty$MODEM ($M $D $HC:$MC $HL:$ML) $TIME minutes.\c"\
>> $LOG
if [ $TIME -lt $GRACE ]
then
echo >> $LOG
fi
fi
if [ $TIME -ge $GRACE ]
then
# Let him have it
P=`ps -ft$MODEM | awk 'BEGIN{FS=" "}/'$U'/{print $2;exit}'`
if [ $P ]
then
kill -9 $P
echo " Killed after $TIME minutes." >> $LOG
else
echo >> $LOG
fi
fi
else
# Nobody logged on from outside
LCK=`ls $SPOOL | egrep "LCK\.\..|.lock"` # locks placed in uucp
if [ "$LCK" -a $TIME -ge $GRACE ] # uucp has hung
then
cd $SPOOL
rm -f $LCK
fi
fi
--
Bob Peirce
uucp: ...!{allegra, bellcore, cadre, idis}
!pitt!darth!investor!rbp
More information about the Comp.unix.wizards
mailing list