ITEM: AE7838L

Implement user time out; logoff inactive users; howto


Env:          AIX 3.2.5

Desc:

    Various modems connected to RS/6000. For these particular ttys,
customer would like a way to hang up the port after x minutes of
inactivity. He has Telebit trailblazers as the modems. Reason to
implement this is that customer has, dedicated long-distance telephone
calls, and users forget to logoff.

Act:

                        How to Log Off Inactive Users

THERE IS NO GUARANTEE THAT THE FOLLOWING SCRIPTS WILL WORK IN YOUR 
APPLICATION.  PLEASE TEST ANY APPLICATION OF THEM CAREFULLY.


Edit the /etc/profile file and uncomment the "TMOUT" variable, then
add it to the "export" line. This determines the number of minutes a
shell can be inactive before being automatically terminated.

This will be affective for all users. If you want it only for 
particular users, it must be added to the user's own .profile (although
they then have the ability to remove it themselves) or you will have
to write shell code to check the user name in the /etc/profile file
before setting the variable.


---------- ---------- ---------- --------- ---------- ----------
A:    The 'TMOUT' parameter is designed to monitor inactivity at the
   shell prompt. Therefore, it cannot be used to log off a user that
   is running a program, regardless of whether the program is active.

      Unfortunately, there is no built in method to automatically
   'timeout' inactive sessions. However, it is possible to do this
   by using the 'w' command. The 'w' command may be used to monitor
   the current system activity of each user, including what the user
   is currently doing, and how long it has been since a keystroke was
   detected.

      Here is a sample of how the 'w' command may be used to accomplish
   the task your customer has requested. Please note that this is just
   an example, and may need modification in order to provide the exact
   functions that your customer needs.

------------------------------------------------------------------------

   PTS=`ps -e | grep sh | grep pts | cut -c8-14`

   for i in $PTS
   do
       MINUTES=`tw -hs | grep $i' ' | cut -c26-27`

       if (($MINUTES > 15))
       then
            echo 'idle time too long'
            PID=`ps -e | grep sh | grep $i' ' | cut -c2-6`
            echo 'killing ' $PID
            kill -9 $PID
       else
            echo 'idle time ok'
       fi
   done

------------------------------------------------------------------------

   It can be run from the command line when necessary, or set to run
   as a cron job that runs throughout the day (for example, invoke the 
   script every 20 minutes). In this script, shells that have been 
   inactive for more that 15 minutes will be killed. Please ensure that 
   this will not cause the customer's application to become a 'zombie'
   or 'ghost' process.

      For more information, please refer to the 'w', 'cut', 'ps', and
   'grep' commands in InfoExplorer.

---------- ---------- ---------- --------- ---------- ----------

========================================================================

Another possible method would be the following script. It uses the
finger command, and a combination of cut and grep commands. Again,
since this script will use the fuser command to kill whatever
processes are running on a port, you need to check that your applications
will not show up as defunct, or in exiting stages.

========================================================================

\#!/bin/ksh
\#
\# Shell script: user_logout.sh
\#
\# This script is made to logoff any user from any terminal (ttys only!)
\# if idle time exceeds a preset limit. It can be modified to be used
\# with either pts, hty, etc.
\# 
\# Place this script in a cron job to be executed every however number 
\# of minutes you wish.
\# i.e
\#  30 * * * * /\/user_logout.sh >>/\/user_logout.out 2>&1
\#
\# NOTE: This will affect ALL terminals across a system-wide basis!

\# Script Variables

IDLE_LIM=20
TM='date'

TTY=`finger -i | grep minute| grep -v hour| grep -v pts| cut -c12-18`

echo '========================================='
echo ${TM}
for i in $TTY
do
        MINUTES=`finger -i | grep $i | grep -v pts| cut -c44-45`
        MIN=${MINUTES}
        if [ $MIN > $IDLE_LIM ]
        then
                echo
                echo 'Idle time on' ${i}  
                echo 'too long, with' ${MIN}
                echo 'min idle'
                fuser -k /dev/${i}
        else
                echo 'Idle time on' ${i}
                echo 'OK'
        fi
        echo
done

\# The above script is-as-is. It is not guaranteed to work with all
\# applications and all conditions. This has been executed under
\# AIX 3.2.5 under normal circumstances.


Support Line: Implement user time out; logoff inactive users; howto ITEM: AE7838L
Dated: January 1995 Category: N/A
This HTML file was generated 99/06/24~13:30:28
Comments or suggestions? Contact us