Hi Gurus,
Thanks to Jim Fitzmaurice, Udo de Boer and Michael R. Mehall.
Jim sent me a script, which I have modified slightly in order
to function as desired. Its final form is the following:
...............
#!/bin/ksh
#
for PROID in `ps aux | grep ftp | grep -v grep | awk '{print $2}'`
do
PHOUR=`ps -fp ${PROID} | awk '{print $5}'|cut -d":" -f1|cut -d "E" -f2`
CHOUR=`date +"%H"`
LIMIT=`expr 8`
if [ ${CHOUR} -lt ${PHOUR} ]
then
ELAPSED=`expr 24 - ${PHOUR} + ${CHOUR}`
else
ELAPSED=`expr ${CHOUR} - ${PHOUR}`
fi
if [ ${ELAPSED} -gt ${LIMIT} ]
then
kill -9 ${PROID}
fi
done
#
..............
A crontab entry runs it three times a day and it is working fine.
Of course it can be modified to kill periodically any processes. Just
change "ftp" to anything else; also the age limit can be modified
by editing the "8" in LIMIT. However test it before running;
comment the kill line and add an echo ${PROID} just to be sure.
Thanks again Jim.
Oyanarte Portilho
Institute of Physics
University of Brasilia, Brazil
========================
Original posting:
Our ftp server has been very busy after it is mirrowing some very solicited
software in the net. A bunch of anonymous ftp processes are not concluded
due to high traffic and stay filling many lines if we give
ps axu|grep ftp
We would like to kill such processes through a script in crontab, when older
than a certain number of hours. We know how to print the time they have
started, with, for instance,
ps aux | grep ftp | grep -v grep | awk '{print $10}'
but do not know how to achieve what we wish, i. e., compare it with the
current time and kill the process if it older then, say, 8 hours.
Any hints ?
Received on Sat Oct 06 2001 - 20:45:33 NZST