Timing out a filepro session in bash
Barry Wiseman
barry at gensoftdes.com
Fri Jul 27 06:26:19 PDT 2007
Barry Wiseman wrote:
> Barry Wiseman wrote:
> let me share the script I've created for myself.
I see I managed to botch the cut-and-paste. Here's a correct copy of the script:
#!/bin/bash
# idleout
# Kill idle sessions by username
#
# 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
done
-----------------------------------------------------------------
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