Limit ouput file on a shell script

I have this one::slight_smile: doing jstack on JVM proccess.

#!/bin/ksh
# ----------------------------------------------------
# capture_jstack.sh    <INTERVAL> <COUNT>
# run jstack and capture output to a log file
#-----------------------------------------------------
#
# scripts and logs are stored
export PROGDIR=/var/tmp/
export LOGDIR=/var/tmp/

# logfile name and location
export LOG_FILE=${LOGDIR}/capture_jstack.${LOGNAME}.log

# write current date/time to log file
echo "#--- $(date) ---"           >> ${LOG_FILE}
cd /usr/jdk/instances/jdk1.5.0/bin/amd64/
for  PID in `ps -ef|grep xxxxx|grep -v grep |awk '{print $2}'`; 
do jstack -m $PID >> ${LOG_FILE}
done;

How do I limit the output log file to 10MB round robin?:confused:

What exactly do you mean by round-robin?
Do yo want to rotate the log file every 10 MB (like create a log1, log2, log3, each with a max size of 10 MB)?
Or, do you only want to keep the last 10 MB of the jstack output?

Just keeping last 10 MB.

The simplest way I can think of is to check the size of the log file after your loop with jstack and use tail -c to dump the last 10MB into a temp file and then rename the temp file to the original LOG_FILE.

However, if your issue is that you do not want the LOG_FILE to ever go beyond 10 MB due to disk space, then you can try putting this check within the loop immediately after the call to jstack (that can still require 20MB of disk space, depending on how much data one call to jstack generates).