Organization: North Dakota Higher Education Computer Network
Newsgroups: bit.listserv.ibmtcp-l
Date:         Tue, 12 Jan 1993 10:18:31 CST
From:         Marty Hoag <NU021172@NDSUVM1.BITNET>
Subject:      Re: SMTP LOGFILE

On Tue, 12 Jan 1993 10:49:37 EST Richard Varenas said:
>Periodically our SMTP 191 disk becomes full as the SMTP LOGFILE grows.
>...
>-Rich

   There is an ONDISKFULL construct in V2R2 but I've never really used that.
We try to manage the space in the 191 minidisk before it fills up.

   We use the SMSG facility to restart SMTP once a day.  In the
PROFILE EXEC we call an exec to rename the SMTP LOG file to SMTPLOG
yyddmmx where x allows for more than one restart a day (on a crash,
IPL, etc).  The exec also removes "old" log files.  Right now we keep
about 10 days comfortably.  All you have to do is authorize whatever
server you use to send the message to REBOOT SMTP (or shutdown then
autolog it).

   The EXEC we use to rename the SMTP LOG and DEBUG (if any) files is called
DODAY EXEC.  Since it is pretty simple minded (consider the author) I'll
include it below.  You'll certainly have to hack it for your environment.
Use it at your own risk...
                             Marty


/*  DODAY EXEC - Manage SMTP LOG and DEBUG files */
/*   DODAY datetype   where datetype is filetype to use to rename
                      SMTP LOG   to  SMTPLOG datetype    and
                      SMTP DEBUG  to SMTPDEBG datetype

     From Marty Hoag, North Dakota State University Computer Center
          nu021172@vm1.nodak.edu / nu021172@NDSUVM1

     Disclaimer:  Use at your own risk.  No warranty is expressed or implied.

     */
   arg datetype .

   keep=10   /* Keep SMTPLOG/SMTPDEBG files just 10 days  */

   temp = date('O')
   year=left(temp,2)
   month=substr(temp,4,2)
   day=right(temp,2)

   if datetype='' then do
      datetype = year||month||day||'A'
      say 'Generated date =' datetype
   end
   else if length(datetype)>8 then do
      say 'Invalid filetype.  Try again.'
      exit 8
   end
   /* Check for existing file */
   count=0
   frc=0
   typesuffix='BCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
   do while frc=0
      'set cmstype ht'
      'statew SMTPLOG' datetype 'A'
      frc=rc
      'set cmstype rt'
      if frc=0 then do   /* Find new name */
         count=count+1
         if count>length(typesuffix) then do
            say 'Cannot find a unique filetype.  Try again...'
            exit 12
         end
         say 'Filetype' datetype 'already exists.  Will generate another.'
         ldt=length(datetype)
         if ldt<7 then ldt=ldt+1
         datetype = left(datetype,ldt-1)||substr(typesuffix,count,1)
      end
   end
   say 'Use' datetype 'for the filetype...'

   'RENAME SMTP LOG A SMTPLOG' datetype 'A'
   rrc=rc

   'RENAME SMTP DEBUG A SMTPDEBG' datetype 'A'

   keepdate=calcdate(left(datetype,6),-1*keep)

   call purgeold 'SMTPLOG'  keepdate 'A'
   call purgeold 'SMTPDEBG' keepdate 'A'

   exit rrc

PURGEOLD:  PROCEDURE;  /* Erase file OLDER than fdatexx */
    parse arg fn fdate fm
    fdl=length(fdate)

    say 'Will purge any' fn 'files on' fm 'with date/type before' fdate'.'

    makebuf
    nq=queued()
    'LISTFILE' fn '*' fm '(STACK DATE NOH'
    nq=queued()-nq
    do nq     /* Pull each line */
       pull tname ttype tmode . . . tblks tdate ttime .
       if left(ttype,fdl)<fdate then do
          'ERASE' tname ttype tmode
          say 'Old File Erased:' left(tname,8) left(ttype,8) left(tmode,2) ,
              'with'right(tblks,5) 'blocks.  rc='rc
       end
    end

    return

/* Calculate Dates Simply */
CALCDATE: PROCEDURE;  /*    olddate=calcdate(yymmdd,days)   */
                      /* or olddate=calcdate(yyyymmdd,days) */

   parse arg current,interval

   ldate=length(current)

   if ldate^=6 & ldate^=8 & ^datatype(current,'W') then do
      say 'Argument Error calling CALCDATE('current','interval')'
      SIGNAL ERROR
   end

   if ldate=6 then do
      yr=left(current,2)
      if yr>50 then yr=yr+1900
      else yr=yr+2000
      mo=substr(current,3,2)
      da=right(current,2)
   end
   else do    /* Length 8 */
      yr=left(current,4)
      mo=substr(current,5,2)
      da=right(current,2)
   end

   LeapYear=isleap(yr)


   days.0='31 28 31 30 31 30 31 31 30 31 30 31'   /* Non-Leap */
   days.1='31 29 31 30 31 30 31 31 30 31 30 31'   /* Leap */
   dpy.0=365
   dpy.1=366   /* Leap days per year */

   day=da
   pmo=mo-1
   if pmo>0 then do i=1 to pmo
      day=day + word(days.LeapYear,i)
   end
   nday=day+interval

   ryr=yr
   rLeapYear=isleap(ryr)
   if nday<1 then do   /* Prev Year */
      do while nday<1
         ryr=ryr-1
         if ryr<1 then do
            say 'Negative Interval Too Large='interval')'
            SIGNAL ERROR
         end
         rLeapYear=isleap(ryr)
         nday=nday+dpy.rLeapYear
      end
   end
   else if nday>dpy.rLeapYear then do   /* Later Year */
      do while nday>dpy.rLeapYear
         nday=nday-dpy.rLeapYear
         ryr=ryr+1
         rLeapYear=isleap(ryr)  /* Lag BEHIND subtraction */
      end
   end
   if ldate=6 then ryr=right(ryr,2,'0')
   else ryr=right(ryr,4,'0')
   rmo=1
   rda=nday
   do while rda>word(days.rLeapYear,rmo)
      rda=rda-word(days.rLeapYear,rmo)
      rmo=rmo+1
   end
   return ryr||right(rmo,2,'0')||right(rda,2,'0')

ISLEAP:  PROCEDURE  /*  true/false = ISLEAP(year)  */
   parse arg yr

   if yr<100 then do
      if yr>50 then yr=yr+1900
      else yr=yr+2000
   end
   return ( yr // 400 = 0 | ( yr // 4 = 0 & yr // 100 <> 0) )
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU