Para o encerramento, este é o começo do script que vou usar. Ele precisa de mais trabalho para torná-lo robusto e fazer logging, mas você deve ter uma ideia geral.
#!/bin/sh
# This script should be executed from a crontab that executes every 5 or 10 minutes
# the find below looks for all log files that do NOT have the sticky bit set.
# You can see the sticky bit with a "T" from a "ls -l".
for x in 'find /home/tomcat/openam/openam/log/ -name "log-*" -type f ! -perm -1000 -print'
do
# Look for open files. For safety, log that we are skipping them
if lsof | grep $x > /dev/null; then
# create a log entry on why I'm not processing this file...
echo $x " is open"
else
# $x "is closed and not sticky"
# run the awk scripts to process the file!
echo $x " processing with awk..."
# Set the sticky bit to indicate we have processed this file
chmod +t $x
fi
done