home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13h.zip / RENLOGS.CMD < prev    next >
OS/2 REXX Batch file  |  1997-11-15  |  5KB  |  155 lines

  1. /* RENLOGS.CMD -- Backup (rename) several of SRE-http's & GoServe'e log files.
  2.     This program is designed to be called by SRE-http's "scheduled program"
  3.     facility (as described in SREFLOGS.DOC).
  4.  
  5. To use this program, you should set the following variables.
  6.  
  7.   i) The LOGFILES. stem variable.
  8.        The LOGFILES. stem variable(s) should contain "log file names"
  9.         you want to backup, and a "renaming pattern".   These "log file name"
  10.        should match the names specified in SREFLOGS.INI.
  11.        The "renaming pattern" is used to create a target file.
  12.  
  13.   ii) VERBOSE
  14.          Set to 1 to report errors. Set to 2 to report all results. Set to 0 to suppress reporting.
  15.  
  16. Examples:
  17.  
  18.   *  LOGFILES.1='D:\GOSERVE\DATA\COMMON.LOG D:\GOSERVE\OLDLOGS\$Y$M$D_C.LOG'
  19.   *  LOGFILES.2='D:\GOSERVE\DATA\REFERER.LOG D:\GOSERVE\OLDLOGS\$D$H??.REF '
  20.   *  LOGFILES.3='D:\GOSERVE\DATA\COMMON2.LOG D:\GOSERVE\OLDLOGS\$Y$M$D_D.LOG'
  21.   *  LOGFILES.0=3
  22.  
  23. **  Note that you MUST set LOGFILES.0 to be equal to the number of LOGFILES. stem variables
  24.      specified.
  25.  
  26. Specifying "renaming patterns":
  27.  
  28.   Each log file mentioned (in LOGFILES.) will be copied to the file
  29.   named by the "renaming pattern".  This "renaming pattern" will have a few strings replacement
  30.   done to it, with the resulting name used as the target file.
  31.   In particular, the following "strings" will be replaced in the "renaming pattern" .
  32.     $Y  = The current 2 digit year
  33.     $M  = The current 2 digit monty
  34.     $D  = The current 2 digit day
  35.     $H  = The current 2 digit hour
  36.     ?   = A random value picked to assure a unique file name.
  37.   All other character (strings) are used as is.
  38.  
  39.   Examples; assuming the time is 2:00 PM on 22 March 1997 --
  40.    *  D:\GOSERVE\OLDLOGS\$Y$M$D_D.LOG' becomes D:\GOSERVE\OLDLOGS\970322_D.LOG
  41.  
  42.    * D:\GOSERVE\OLDLOGS\$D$H??.REF  (might) become D:\GOSERVE\OLDLOGS\220201.REF
  43.          (The ?? would yield 02 if 220201.REF already existed).
  44.  
  45. Notes:
  46.   * The files will be copied and then deleted. Thus, the target (the renaming pattern)
  47.     can be on a different drive.
  48.   * See SREFLOGS.INI for more details on selection of common, browser, and referer
  49.     log files.
  50.   * See SREFLOGS.INI for a discussion of how to use the SCHED. parameters to
  51.      create scheduled backups (you should coordinate your SCHED. parameters and
  52.      your "renaming patterns".
  53.  
  54. */
  55.  
  56. /* BEGIN USER CHANGABLE CODE ................................................... */
  57.  
  58. logfiles.0=0
  59.  
  60. verbose=1
  61.  
  62.  
  63. /* END USER CHANGABLE CODE ..................................................... */
  64. /* END USER CHANGABLE CODE ..................................................... */
  65. /* END USER CHANGABLE CODE ..................................................... */
  66.  
  67. rename_logs:
  68. if verbose>1 then call pmprintf_sref(' Archiving SRE-http Log files. ....')
  69.  
  70. if symbol('LOGFILES.0')<>'VAR' then logfiles.0=0
  71.  
  72. hh=time('h')
  73. if hh<10 then hh="0"||hh
  74.  
  75. addd=date('o')
  76.  
  77. parse var addd yy '/' mm '/' dd .
  78. yy=strip(yy); mm=strip(mm); dd=strip(dd); hh=strip(hh)
  79. if length(yy)<2 then yy="0"||yy
  80. if length(mm)<2 then mm="0"||mm
  81. if length(dd)<2 then dd="0"||dd
  82. do imm=1 to logfiles.0
  83.    parse var logfiles.imm asource atarget1
  84.    atarget=fix_name(atarget1)
  85.   
  86.   foo=doscopy(strip(asource),strip(atarget),'R')
  87.   if foo<>0 then do
  88.       call pmprintf_sref(' REXXLIB DOSCOPY error (' foo ') copying log file ' asource ' to  ' atarget1)
  89.   end  /* Do */
  90.   else do
  91.      foo=sysfiledelete(asource)
  92.      if verbose>1 then call pmprintf_sref(asource ' moved to ' atarget)
  93.   end  /* Do */
  94. end
  95.  
  96. return 0
  97.  
  98. /************/
  99. fix_name:procedure expose hh mm dd yy
  100. parse upper arg aname
  101. new1=sref_replacestrg(aname,'$Y',yy,'ALL')
  102.  
  103. new1=replacestrg(new1,'$M',mm,'ALL')
  104. new1=replacestrg(new1,'$D',dd,'ALL')
  105. new1=replacestrg(new1,'$H',hh,'ALL')
  106. if pos('?',new1)>0 then new1=dostempname(new1)
  107. return new1
  108.  
  109.  
  110. replacestrg:
  111.  
  112. exactmatch=0
  113. backward=0 ; doall=0
  114.  
  115. parse arg astring ,  target   , putme , type , exactmatch
  116.  
  117. type = translate(type)
  118. if type="BACKWARD" then backward="YES"
  119. if type="ALL" then doall="YES"
  120.  
  121. iat=1
  122. joelen=length(target)
  123. joelen2=length(putme)
  124.  
  125. doagain:                /* here if doall=yes */
  126.  if exactmatch="YES" then do
  127.     if   backward="YES" then
  128.         joe= lastpos(target,astring)
  129.     else
  130.         joe= pos(target,astring,iat)
  131.  end
  132.  else do
  133.    if   backward="YES" then
  134.         joe= lastpos(translate(target),translate(astring))
  135.     else
  136.         joe= pos(translate(target),translate(astring),iat)
  137.  end
  138.  if joe=0 then
  139.          return astring
  140.  
  141.  astring=delstr(astring,joe,joelen)
  142.  if putme<>' ' then
  143.     astring=insert(putme,astring,joe-1)
  144.  
  145.  if doall="YES" then do
  146.      iat=joe+joelen2
  147.      signal doagain
  148.  end
  149. /* else, all done */
  150.  return astring
  151.  
  152.  
  153.  
  154.  
  155.