#!/bin/sh # # AUTHOR: Bill Facey DATE: 7 Feb 1996 # Modified By: Robert Grumbine 10 Sep 1997 # Modified By: David Michaud 12 Mar 1999 # FOR IBMSP # # Original: # This script manages logfiles listed in loop below. # When they exceed $KEEPJLOG lines they are renmaed to ${logfile}.old # and a new logfile is started up. # # Modification: # In order to have the logfile on hand for diagnostics after a # weekend, maximum number of lines is set to MAXJLOG. Execution # of the manager is moved to the ADMIN net, and out of scripts # callable by users. In moving to the jlogfile.old, the last MAXJLOG # lines are retained in jlogfile for diagnosing recent problems. # As part of ADMIN net, this script is run every 6 hours. # The logfiles are kept up to the MAXJLOG entries in a series of files, # each KEEPJLOG lines long, and named ${logfile}.old.$n where n # runs from 1 to MAXJGLO/KEEPJLOG (integer division) + 1. # #Start SMS $SMSBIN/smsinit set -x # # MAXJLOG = Maximum number of lines to permit # KEEPJLOG = Number of lines to retain # lc = Line counter # for log in jlogfile snd2forgn_log do case $log in jlogfile) MAXJLOG=75000 KEEPJLOG=5000 logfile=/com/logs/jlogfile;; snd2forgn_log) MAXJLOG=30000 KEEPJLOG=10000 logfile=/com/logs/snd2forgn_log;; *);; esac NLOG=`expr $MAXJLOG \/ $KEEPJLOG + 1` lc=`wc -l ${logfile} | awk '{print $1}'` set +x echo "" echo "lc=$lc NLOG = $NLOG, MAXJLOG=$MAXJLOG, KEEPJLOG=$KEEPJLOG " echo "" set -x # # When logfile gets more that twice the size of KEEPLOG, start the # moving and recopying. MAXLOG specifies how may of these # files we'll keep around. # linelim=`expr $KEEPJLOG \* 2` if [ "$lc" -gt "$linelim" ] ; then cp ${logfile} ${logfile}.old rel=`expr $lc - $KEEPJLOG` tail -n +$rel ${logfile}.old > ${logfile} echo "" echo "HIT CTRL-C AND RESTART SCROLLING JLOGFILE." >> ${logfile} echo "" msg="Z ${logfile} restarted." unset time time=`date -u | cut -f2-5 -d ' '` echo "${time}${msg}" >> ${logfile} # # Now start the progressive aging of the old.N files to keep the most # recent NLOG present: # j=2 k=`expr $j - 1` while [ $j -le $NLOG ] do if [ -f ${logfile}.old.$j ] ; then mv ${logfile}.old.$j ${logfile}.old.$k else touch ${logfile}.old.$k fi j=`expr $j + 1` k=`expr $j - 1` done # # The following is to ensure no overlap between the live log and the # archived log. # lc=`wc -l ${logfile}.old | awk '{print $1}'` k=`expr $lc - $KEEPJLOG ` head -n $k ${logfile}.old > ${logfile}.old.$NLOG rm ${logfile}.old else set +x echo "" echo "${logfile} doing fine" echo "" set -x fi done $SMSBIN/endt