Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!brl-tgr!tgr!RSanders@DENVER.ARPA From: RSanders@DENVER.ARPA Newsgroups: net.sources Subject: idle terminal killer - 4.2 BSD Message-ID: <10092@brl-tgr.ARPA> Date: Sun, 21-Apr-85 02:33:40 EST Article-I.D.: brl-tgr.10092 Posted: Sun Apr 21 02:33:40 1985 Date-Received: Tue, 23-Apr-85 00:47:48 EST Sender: news@brl-tgr.ARPA Lines: 42 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