Timing out a filepro session in bash
Barry Wiseman
barry at gensoftdes.com
Thu Jul 26 12:50:35 PDT 2007
Barry Wiseman wrote:
>
> Can someone suggest a fix or a better method of timing out idle filepro sessions?
>
So, I've discovered that TMOUT is not my friend at all (it only has to do with those
times when the shell is idle waiting for interactive keyboard input; once you launch
a program it has no effect). As long as I'd posted this (totally OT as it turns out)
question on the list, let me share the script I've created for myself. It is written
for use with remote ssh sessions and will select by IP address, but could easily be
changed to username instead.
Tested on White Box 3.0 (a downstream repackaging of RHEL 3.0). Other flavors/OS's
may need adjustment.
#!/bin/bash
# idleout
# Kill sessions by address which are idle 1-60 minutes
#
# Should be run as a cron job:
#
# * * * * * /usr/local/bin/idleout 10.0.0.172 3
#
# This will terminate any/all sessions originating from 10.0.0.172
# which have been idle three minutes or longer
IP=$1
TIMEOUT=$2
LOG=/var/log/idleout.log
dohim() {
echo -e " Ready to kill pid's on $TTY" >>$LOG
PIDS=""
ps -t $TTY | while read ps_line
do
set $ps_line
[ $1 = PID ] || {
echo -e "\tKilling $1" >>$LOG
###### Comment this out for testing ######
kill -9 $1
###### Comment this out for testing ######
}
done
}
echo "---------- `date` ---------------" >>$LOG
w | grep $IP | while read w_line
do
set $w_line
USER=$1
TTY=$2
WIP=$3
IDLE=$5
echo "IP ${WIP}: User $USER on tty $TTY idle $IDLE " >>$LOG
case $IDLE in
*[0-9]s) # Idle time is in seconds, forget this guy
continue ;;
*m) # Idle time is in hours, do him
dohim ;;
*days) #Idle time is in days, do him
dohim ;;
*) # Idle time is in mm:ss format
Minutes=`echo $IDLE | cut -d: -f1`
[ $Minutes -ge $TIMEOUT ] && dohim
;;
esac
-----------------------------------------------------------------
Barry Wiseman barry at gensoftdes.com
Genesis Software Designs, Inc. Voice: (212) 889-9191
55 West 45 Street, New York, NY 10036 Fax: (212) 889-1589
-----------------------------------------------------------------
More information about the Filepro-list
mailing list