home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / rexx / library2 / chckdmns / chckdmns.cmd
OS/2 REXX Batch file  |  1992-10-26  |  3KB  |  83 lines

  1. /*
  2.     CHECK_DEAMONS.CMD
  3.     (C)1992 Turgut Kalfaoglu <TURGUT@FRORS12.BITNET>
  4.  
  5.  This program will monitor the deamons it knows about, every <interval> 
  6.  minutes (you define the intervals, default=2), restarting them, if they 
  7.  are not active, and terminating them if there are too many copies of it 
  8.  active.  
  9.  
  10. Syntax of the deamon. stem:
  11.  
  12.    <name of the deamon> <required_number_of_copies> <entire command>
  13.  
  14. name of the deamon: as it appears to PROCS.EXE
  15. required_number_of_copies: The number of copies of this deamon that must
  16.  be active. Use * if any number of copies may be present, but at LEAST 
  17.  one copy must be active.
  18. entire_command: this is the command needed to restart the deamon.
  19.  
  20. This program is useful to keep your system checked continuously at your 
  21.  absence. Especially some releases of SENDMAIL are prone to proliferate 
  22.  into multiple copies. This program should cure that.
  23.  
  24. This program requires - a shareware package that displays the processes 
  25.  running, which also comes with a program to stop these processes. This 
  26.  package contains two programs: PROCS.EXE and KILLEM.EXE. Available from
  27.  many sources, including listserv@blekul11, and ftp-os2.nmsu.edu
  28.  
  29. *****************************************************************/
  30.  
  31. interval = 2  /* in minutes */
  32. deamon.  = ''
  33. deamon.1 = 'SENDMAIL.EXE 1 DETACH SENDMAIL -bd -q30m'
  34. deamon.2 = 'LAMAIL.EXE 1 START /MIN LAMAIL'
  35. deamon.3 = 'LPRMON.EXE 1 DETACH LPRMON LPT1:'
  36. deamon.4 = 'FTPD.EXE * START /MIN FTPD'
  37. deamon.5 = 'INETD.EXE 1 START /MIN INETD'
  38.  
  39. Call RxFuncAdd 'SysSleep','RexxUtil','SysSleep'
  40. '@ECHO ON'
  41. do z=1 while deamon.z \=''
  42. end /* do */
  43. maxdeamon = z-1
  44. 'CLS'
  45. say time() 'Deamon Monitor Up and running, monitoring' maxdeamon,
  46.  'deamons.'
  47.  
  48. do forever
  49.    '@PROCS /S > \tmpfile.out'
  50.    line="?"
  51.    count. = 0
  52.    do linenum=1 while (line > "" | linenum<30)
  53.       line = LINEIN("\tmpfile.out")
  54.       parse var line . . procname .
  55.       do z=1 to maxdeamon
  56.          if word(deamon.z,1) = procname then 
  57.             count.z = count.z+1
  58.       end /* do */
  59.    end
  60.    r = LINEOUT("\tmpfile.out",,) /* finis */
  61.    do z=1 to maxdeamon
  62.       parse var deamon.z deamonname maxcopies startcmd
  63.       if count.z = 1 & maxcopies = '*' Then Iterate
  64.       if count.z \= maxcopies then do
  65.         if maxcopies \= '*' Then Do
  66.           say time() 'Found' count.z 'copies of' deamonname'.' 
  67.           if count.z>maxcopies then do
  68.               say time() 'Terminating' deamonname 'deamon(s).'
  69.               'KILLEM' deamonname
  70.           end
  71.         End
  72.         maxcpy = maxcopies
  73.         if maxcpy = '*' then maxcpy=1
  74.         say time() 'Re-activating' maxcpy 'copies of' deamonname
  75.         do t=1 to maxcpy
  76.            interpret '"'startcmd'"'
  77.         end /* do */
  78.       end /* if */
  79.    end /* do */
  80.    Call SysSleep  interval*60
  81. end
  82.  
  83.