Kill idle script is killing unnecessarly

Hi All,I have a problem with my kill idle script.my script is supposed to kill the user sessions which are idle for more than 2 hours.But is is killing the sessions which are idle for less than 2 hrs also.I dont know the exact time after which the script is killing,but it is less than 2 hours i am sure.I faced this problem personelly with my session also.i opened a new session of my application and after half an hour or so it got killed by the shell idle script.Here I am giving my kill idle script.Please if any one can make it out where the problem is that could be great.

#!/bin/sh
# This script will kill the users listed in the file $SELECTUSERS that are idle for the time equal to or greater then $IDLETIME. IDLETIME is in hours
. /run/pronto/lib/sh_environs 
IDLETIME=2; export IDLETIME
# ERRORLOG=$PRONTO/lib/kill-idle/error.log; export ERRORLOG
KILLIDLELOG=$PRONTO/lib/kill-idle/kill-idle.log; export KILLIDLELOG
USERSLOG=$PRONTO/lib/kill-idle/users.log; export USERSLOG
SELECTUSERS=$PRONTO/lib/kill-idle/users; export SELECTUSERS 
# below is for sunos
who -u | /usr/xpg4/bin/grep -i -f $SELECTUSERS|/usr/xpg4/bin/awk '{print $1 "," $2 "," $6 "," $7}' > $USERSLOG
for line in `cat "$USERSLOG"`
do
NAME=`echo $line | /usr/xpg4/bin/awk -F "," '{print $1}'`
PTS=`echo $line | /usr/xpg4/bin/awk -F "," '{print $2}'`
##Below is for hrs timeout
TIME=`echo $line | /usr/xpg4/bin/awk -F "," '{print $3}' | /usr/xpg4/bin/awk -F ":" '{print $1}'`
## Below is for minutes timeout
# TIME=`echo $line | /usr/xpg4/bin/awk -F "," '{print $3}' | /usr/xpg4/bin/awk -F ":" '{print $2}'`
if [ "$TIME" -ge "$IDLETIME" ] 
then
echo `date` >> $KILLIDLELOG
echo "PTS = $PTS" >>$KILLIDLELOG
PID=`ps -ef | /usr/xpg4/bin/grep "$PTS" | /usr/xpg4/bin/grep "pronto" | /usr/xpg4/bin/awk '{print $2}' | head -1`
echo "PID is $PID" >>$KILLIDLELOG
echo "name is $NAME" >>$KILLIDLELOG
echo "Idle time is $TIME hrs" >>$KILLIDLELOG
echo "kill $PID" >>$KILLIDLELOG
echo "" >>$KILLIDLELOG
kill -5 $PID
fi
done
exit

First, $3 is not giving the time but date.
second, you need to calculate the time by substrating "time now" with the time the user logged in and compare that against the specified time.

hi devtakh,

I could not get you ....so can you please expalin me where i am missing the logic and explain the way to rectify the issue.

many thanks,
prabhu

Some areas where the script could go wrong:

1) If is run from cron too frequently runs could overlap.

2)

If one username is contained in another user name you could get a false match. e.g. "fred" and "alfred" . Depends on what your usernames are like.

3)

Lots of scope for false mismatches. Consider similar PTS values "pts/aa" and "pts/aab" .
No point in running "ps -ef" because we already know $PTS. Try "ps -ft"${PTS}". This will make the script faster and reduce the chance of false matches.
Also the the second "grep" in the pipeline could find the first "grep" in the pipeline.

Could be better with something like this which allows for the user to log out since we started our script. Also reduces chance of false matches. I don't know whether the "head -1" is needed as I know nothing about your process table.

I have never issued a "kill -5" but I assume that it means something to "pronto"?