Discussion Locked

Ending User Processes via Cron

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am using a IBM AIX 4.2 and have a minor nuisance that I would like to eliminate. Each day, I have users that incorrectly close a telnet application that they use to reach the AIX machine and as a result that user is still active on the server. Iwant to use cron to query the active users at a particular time of day and kill all processes for those users that have not been active for more than two hours.

5 replies

by peter.moy

Really, its best if your telnet application maintains its own inactivity timer. It can do a managed shutdown once the user has been inactive for the proscribed period.

However, the 6th column of "who -u" command gives the idle time for each logged user pseudo tty if you telnet application is using a pseudo tty. You can use this data in a script to terminate any process associated with the tty that has not been using for a defined inactivity period.

Alternatively, if your telnet client application has half closed its TCP/IP socket, you can put shorten the keepalive inactivity timeout on your sockets. The default this is 2 hours is really only appropriate for internet application and should be shortened to something like 10 minutes forservers used for client/server applications. This is with the command:

no -o /dev/tcp tcp_keepidle 1200

Finally, if none of these alternatives is appropriate, you could try using comparing the output of periodiodic execution of netstat of telent connections that have been inactive for the defined period, you can then find which of your server processes has the socket connection open using sonething like lsof.

by jbullard

You could use a script like this (BE SURE TO READ THE NOTE AT THE END):

who -u|while read name term month day time idle pid comment
do
bye=0
case $idle in
.) bye=0
;;
[2-24]:[0-9][0-9]) bye=1
;;
esac
if [ $bye -eq "1" ]
then
xout $term $name $idle $pid
fi
done

xout()
{
a=`grep -c $2 /usr/contrib/bin/autolog.prot`
if [ $a != 1 ]
then
kill -15 $4 1>/dev/null 2>&1
fi
}

NOTE: make sure that you have a file like "autolog.prot" that contains usernames of people who you DON'T want to log out (like root and yourself :)). Just call this script from a cron and it will kill anyone who has been idle from 2 to 24 hours.

This discussion is closed to new replies.