We are running 4.25 and TCP/IP 5.0 and allow remote access to our computer using inetd. However, we have some users who leave their sessions open for days at a time.
I would like to be able to kill processes that have been idle for some amount of time. Would anyone already have a script file to do this?
I’ve been working a script myself and have found the “who -o” will give me the idle time I’m looking for, but when I try using sin or ps to get the PID to kill, the times being reported are not actually idle time.
Here is what I’ve tried if anyone has any suggestions:
who -i | grep -v -e System -e root -e Userid > $TMP
users=awk '{n=split($6,a,":"); if( n >=3 && a[1] >= 8 ) \ { print $1 } }' < $TMP
for u in $users; do
time=date "+%H:%M%, %m/%d/%y"
processes=ps -F"%p %T %c" -u $u | awk '{ n=split($2,a,":"); \ if ( n >= 3 && a[1] >= 8 ) { print $1 } }'
if [ “$processes” != “” ]
then
echo “---------------------------------------------------------------” >> $LOG
echo " Killing idle tasks for $u on node $NODE at $time" >> $LOG
echo “---------------------------------------------------------------” >> $LOG
for p in $processes; do
sin -p$p >> $LOG
done
kill -9 $processes
fi
done
/usr/local/bin/Mail -s “Idle tasks” admin < $LOG
Thanks,
Tony