Two possibilities -
1) Create a cron job to run let's say every 15 minutes or so -
00,15,30,45 * * * * /path/to/the/script
2) Run it in background, have it wake up every 15 minutes -
#!/bin/ksh
interval=900
hwm=80
numtop=1
log=/tmp/tops.log
while true
do
if [ $(vmstat 1 1 | tail -1 | awk "{print $14 + $15}") -gt $hwm ]
then
date >> $log
ps -ef -o comm -o pid -o pcpu | sort -k3nr | head -$numtop >> $log
echo "----------------------------" >> $log
fi
sleep $interval
done
exit
Configure the desired interval (in seconds) by modifying interval=...
and start the script with
nohup /path/to/the/script &
Please take care to watch the size of your logfile, as it will of course grow over time.
wmp