RSanders@DENVER.ARPA (04/21/85)
The following is a shell script/crontab line we've had running for more than a year. We have about 24 ports and about 100 terminals meeting at a nicely wood-crafted plugboard, so contention is a problem. Sorry, no man page for this one - but carefully note the bug comment. This works for us on VAX/4.2 BSD, and SUN 1/4.2 BSD. Note that the "echo -n" lines are supposed to have control-G's between the "". I don't know if they will make it past various mailers. -- Rex ............................................................................. #! /bin/sh # idlekill - kills idle logins # Rex Sanders, USGS Pacific Marine Geology, 4/24/84 # modified 6/84 - CRONTAB warning, remove log - RS # modified 12/84 - use 'w' instead of 'wi' - RS # modified 4/85 - add lots more beeps to warning - RS # # BUG: if a user is in a process for a long time that uses /dev/tty # directly (as in 'cc junk.c |& error -v'), 'w' reports idletime # incorrectly, and may unjustly kill a login. # IDLEKILL is minutes of idle terminal before death eligibility IDLEKILL=30 # CRONTAB is minutes between times idlekill is run by cron as in: # 2,12,22,32,42,52 * * * * /etc/idlekill CRONTAB=10 WARN=`expr $IDLEKILL - $CRONTAB` for j in `/usr/ucb/w -h | awk "{if (substr(\$0,27,2)*60+substr(\$0,30,2)+0 >= $IDLEKILL) print \$2 }"` do i=`expr $j : 'tty\(.*\)' '|' $j` echo "Your login is being killed for more than $IDLEKILL minutes of inactivity!" > /dev/$j echo `date` > /dev/$j kill -9 `ps -t${i} | awk '/ -.*sh /{print \$1}'` done for j in `/usr/ucb/w -h | awk "{if (substr(\$0,27,2)*60+substr(\$0,30,2)+0 >= $WARN) print \$2 }"` do echo -n "" > /dev/$j echo "Your login will be killed in the next $CRONTAB minutes!" > /dev/$j echo -n "" > /dev/$j done