General discussion

Locked

Ending User Processes via Cron

By dadzierzak ·
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.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Ending User Processes via Cron

by peter.moy In reply to Ending User Processes via ...

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.

Collapse -

Ending User Processes via Cron

by dadzierzak In reply to Ending User Processes via ...

The question was auto-closed by TechRepublic

Collapse -

Ending User Processes via Cron

by jbullard In reply to Ending User Processes via ...

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.

Collapse -

Ending User Processes via Cron

by dadzierzak In reply to Ending User Processes via ...

The question was auto-closed by TechRepublic

Collapse -

Ending User Processes via Cron

by dadzierzak In reply to Ending User Processes via ...

This question was auto closed due to inactivity

Back to Linux Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums