Program to log off idle users

Rob McMahon cudcv at warwick.ac.uk
Thu Oct 4 23:53:33 AEST 1990


I'm guessing a bit at this script, because it's full of SystemV-ism's, and
this article is not about critising code, but ...

In article <9800001 at hpbbi4.BBN.HP.COM> eugen at hpbbi4.BBN.HP.COM (#Eugen Bauknecht) writes:
>who -u | awk '{print $2,$6}' > /tmp/kltmp0

(Sorry what's who -u ?  Is this a System-V ism ?  I'll assume $2 is the
terminal, and $6 is the `idle time', got by checking the mtime & atime of the
tty).

>cat /tmp/kltmp0 | awk '{ if ($2>=1) print $1 }' >> /tmp/kltmp1
>var=`cat /tmp/kltmp1` ;export var
>for i in $var

(I don't get this, what's wrong with "for i in `cat /tmp/kltmp1`" ?  Why
export $var ?)

>    do
>    ps -ft $i >> /tmp/kltmp2
>done

(I don't actually know what -ft is either, I'll assume it prints out the
processes attached to some terminal specified by the t option, in some format
specified by the f option.)

>cat /tmp/kltmp2 2>/dev/null| awk '{if ($2 !="PID") print $2}' >>/tmp/kltmp3
>sort -rn -o/tmp/kltmp4 /tmp/kltmp3
>var=`cat /tmp/kltmp4`
>kill -9 `echo $var` 2>/dev/null

(Weird, what's wrong with kill -9 `cat /tmp/kltmp4` ? )
Aaagh!  Please don't just `kill -9' at least do a `kill -1' first, maybe
followed a few seconds later by a plain `kill' before getting that drastic.
Preferably send the process group of the terminal a SIGHUP, and then just kill
the shell if it doesn't go away of it's own accord.

The trouble with all these idle timeout schemes is that they rely on the idle
time on the particular /dev/tty device.  

1) You don't really want to kill all such sessions, what about people who just
have a window open from their workstation, or are running a dumb terminal pty
handler like `screen', `pty', ...  Against that you probably do want to kill
people who have come from a terminal server, so you have to do some horrible
kludges along the lines of

	if ( hard-wired-terminal ||
	     pseudo-terminal-coming-from-terminal-server ) ...

2) This just doesn't work.  If an application is talking to /dev/tty instead
of the particular port, it's the times on /dev/tty, not /dev/tty?? that get
updated.  Our most popular editor round here works like this.  Even the ones
that try to be clever and go hunting down the process list looking for busy
processes don't work, after 127 seconds you can't tell how long a process has
been idle:

I can assure you I was typing at this editor just 2 minutes ago:

Script started on Thu Oct  4 14:37:27 1990
cudcv (41) >> w
  2:37pm  up 6 days,  6:56,  26 users,  load average: 1.28, 0.48, 0.47
User     tty       login@  idle   JCPU   PCPU  what
root     console   7:32am  6:45   2:24     40  -csh 
...
cudcv    ttyq6     2:10pm    27      1         ded xx 
...
cudcv (42) >> sps vt q6
Ty User     Status Fl Nice Virt Res %M  Time Child %C Proc# Command
q6 cudcv    pause          248    0  0   1.4+  1.3  0 20328 -tcsh
q6. *       rttyq6          80    0  0   0.1        0 20345 ded xx
154 (13488k) processes, 1 (624k) busy, 57 (8072k) loaded, 96 (16952k) swapped
cudcv (43) >> pstat -p
154/1034 processes
   LOC    S    F PRI      SIG  UID SLP TIM  CPU  NI   PGRP    PID   PPID  RSS SRSS  SIZE    WCHAN     LINK
...
f8197824  1 8000  28        0   60 127  25    0  20  20345  20345  20328    0    8     a ff14be20 f8195858
...
f8198164  1 8200  40        0   60 127 127   29  20  20328  20328  20327    0   29    1f ffffc000 f819872c
...
cudcv (44) >> x
exit

script done on Thu Oct  4 14:38:06 1990

So how do you tell I hadn't really gone away for 27 minutes, but just stopped
to follow up to this article ?  I seriously would like to know the answer,
because we get dozens of naive users who do just walk away from the terminal,
and yes, we do tell them the importance of logging out.  The lucky ones just
get a nasty piece of mail from me.  The unlucky ones have all their files
moved to a `...' directory and come crying to me for help.  The really unlucky
ones have all their files removed (yes, I have seen this).

Rob
--
UUCP:   ...!mcsun!ukc!warwick!cudcv	PHONE:  +44 203 523037
JANET:  cudcv at uk.ac.warwick             INET:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.unix.admin mailing list