Path: utzoo!mnetor!uunet!ccicpg!turnkey!conexch!root From: root@conexch.UUCP (Larry Dighera) Newsgroups: comp.unix.questions Subject: Re: Want login shell to timeout after 15 mins. Message-ID: <176@conexch.UUCP> Date: 1 Jan 88 19:02:52 GMT References: <3341@umn-cs.cs.umn.edu> Reply-To: root@conexch.UUCP (Larry Dighera) Organization: The Consultants' Exchange, Orange County, CA. (714) 842-6348 Public Access Lines: 127 Keywords: Sys-V, idle, logout Summary: How to log out idle users In article <3341@umn-cs.cs.umn.edu> choudhur@umn-cs.cs.umn.edu (Tahsin Choudhuri) writes: > >Ques: Is it possible to make the login shell to time-out, > (i.e. kill itself) if for 15 minutes lets say nothing > has been typed on the terminal. I am running C-shell > under ATT Sys-V. >=============================================================================== >Tahsin Choudhuri, Computer Science Dept. University of Minnesota, Mpls, MN 55455 Tahsin: There are several ways to do this. The simplest is to get a copy of the Korn Shell which supports an environment variable, TMOUT, which if set to a value greater than zero, will terminate the shell if a command is not entered within the prescribed number of seconds. You could set the value of this variable in /etc/profile and then set it to read-only status to prevent users from changing it. Here is a copy of a shell program that was published in Unix World magazine recently. It will log out idle users: # #LOGFILE=/usr/adm/autolog2 # logging file #MAXTIME=15 # allowed idle time #TZ=EST8EDT; export TZ # needed for date ## set -x # for debugging ## Examine all logged in accounts # #who| sed 's/:/ /'| #while read LINE #do # set $LINE # uid=$1 # tty=$2 # date="$3 $4 $5:$6" # ## Calculate time since last access # # ttytime=`ls -lu /dev/$tty |sed 's/:/ /'| # awk '{printf "%d", $9 * 60 + $10}'` # # We don't want to calculate curtime statically # # before entering this loop; it can get stale..... # # Calculate current time in minutes: # curtime=`date |sed 's/:/ /g' |awk '{printf "%d", $4 * 60 +$5} '` # # curtime checked AFTER ttytime to prevent negative idle # # due to gross clock granularity # # port logoff # case $2 in # tty14) # MAXTIME=6;; # tty22) # MAXTIME=6;; # *) ;; # esac # #if test "/dev/$tty" = /dev/tty14 # #then # #MAXTIME=600 # #else # #MAXTIME=15 # #fi # idle=`expr $curtime - $ttytime ` # # Try to handle midnight wraparounds properly # if [ $idle -lt 0 ]; then # idle=`expr 24 \* 60 - $ttytime + $curtime` # fi # if [ $idle -ge $MAXTIME ]; then # echo "" >> $LOGFILE # echo `date` $uid $tty WARNING >> $LOGFILE # echo "\n\007\007 # $uid, you have been idle longer than $MAXTIME minutes # you will be logged off # unless you press # \007\007 # ">/dev/$tty # # # Calculate the new terminal device access time # # after the warning message is sent to the terminal # before=`ls -lu /dev/$tty|sed 's/:/ /'| # awk '{printf "%d", $9 * 60 + $10}'` # sleep 30 # # Calculate the terminal device access time after 1 minute # # after=`ls -lu /dev/$tty |sed 's/:/ /' | # awk '{printf "%d", $9 * 60 + $10}'` # # If access time is the same, waste the turkey # if [ $before -eq $after ]; then # echo "`date` $uid ++ logged-off++">>$LOGFILE # echo "Logged off--excess idle time `date`"|mail $uid # # # Get abbreviated terminal number # case $tty in # console) stty='co';; # *) stty=`expr "$tty" : 'tty\(.*\)'`;; # esac # # Kill all processes created by that terminal # # in reverse numerical order # # ps -eax required on Pyramid; ps -e on others... # for i in `who -u| # awk "{if (\\$2 == \"$tty\") print \\$1}"|sort -nr` # do # kill $i # sleep 5 # kill -1 $i # done # fi # fi #done # But, the most comprehensive session monitoring program that I have run across is UNTAMO. It not only allows logging out idle terminals, but a System Administrator can also set session time limits based on username, group, port, and restrict a user from multiple logins. There is a version of untamo patched for Xenix in /usr/spool/uucppublic/untamo.tar.Z on conexch. Feel free to uucp it to your site if you like. Best Regards, Larry Dighera -- USPS: The Consultants' Exchange, PO Box 12100, Santa Ana, CA 92712 TELE: (714) 842-6348: BBS (N81); (714) 842-5851: Xenix guest account (E71) UUCP: conexch Any ACU 2400 17148425851 ogin:-""-ogin:-""-ogin: nuucp UUCP: ...!ucbvax!ucivax!mickey!conexch!root || ...!trwrb!ucla-an!conexch!root