home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / SWAPSIZE.ZIP / SWAPSIZE.CMD next >
OS/2 REXX Batch file  |  1992-04-06  |  5KB  |  210 lines

  1. /*
  2.  * OS/2 REXX Program: SWAPSIZE.CMD
  3.  * Version: 2.0
  4.  *
  5.  * Written by:      Bob Mahan
  6.  *                  November, 1991
  7.  *
  8.  * Description:     This is a simple REXX program that polls the OS/2
  9.  *                  Swapper file, the drive it resides on, and displays
  10.  *                  the results in an OS/2 window.  The polling occurs
  11.  *                  every second by default.
  12.  *
  13.  * Command Syntax>> SWAPSIZE -.--------------------.-------------> <
  14.  *                            `- n -.------------.-'
  15.  *                                  `- drive(s) -'
  16.  *
  17.  *
  18.  * Arguments:       n = number of seconds to delay between querys
  19.  *                      default of 1 display every second
  20.  *                  drive(s) = one or more drives (x:) to monitor
  21.  *                             default of drive with SWAPPER.DAT
  22.  *
  23.  * Notes:           This REXX program has been heavily commented and
  24.  *                  performance improvements can be gained by removing
  25.  *                  the comments.
  26.  *
  27.  * Modifications:   4/92 - Added display option for additional drives
  28.  *                         to be monitored
  29.  */
  30.  
  31. /*
  32.  *  Initialize break processing and REXX functions
  33.  */
  34.  
  35. SIGNAL ON HALT NAME EndIt
  36.  
  37. CALL RxFuncAdd 'SysDriveInfo', 'RexxUtil', 'SysDriveInfo'
  38. CALL RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  39.  
  40. /*
  41.  *  Initialize Program
  42.  */
  43.  
  44. delay = 1       /* default sleep time in seconds */
  45. suffix = 0      /* display 'M' suffix of sizes (0=off,1=on) */
  46.  
  47. swapfile = 'D:\TEMP\SWAPPER.DAT'
  48. numdrvs = 1
  49. PARSE VAR swapfile scandrv.numdrvs '\' garbage
  50.  
  51. /*
  52.  *  Parse command line for delay override argument
  53.  */
  54.  
  55. IF ARG() <> 0 THEN
  56.   DO
  57.     PARSE UPPER ARG delay scandrv.1 scandrv.2 scandrv.3 scandrv.4 scandrv.5
  58.     IF scandrv.1 = '' THEN
  59.       DO
  60.         numdrvs = 1
  61.         PARSE VAR swapfile scandrv.numdrvs '\' garbage
  62.       END
  63.     ELSE
  64.       DO n = 1 TO 5
  65.         IF scandrv.n <> '' THEN
  66.           DO
  67.             numdrvs = n
  68.             IF LENGTH(scandrv.n) = 1 THEN scandrv.n = scandrv.n||':'
  69.           END
  70.       END
  71.   END
  72.  
  73. /*
  74.  *  Initialize ANSI colors
  75.  */
  76.  
  77. '@ANSI ON > NUL'
  78.  
  79. color.time = '1B'x || "[37m" || '1B'x || "[40m"
  80. color.ok   = '1B'x || "[32m" || '1B'x || "[40m"
  81. color.warn = '1B'x || "[33m" || '1B'x || "[40m"
  82. color.bad  = '1B'x || "[31m" || '1B'x || "[40m"
  83.  
  84. /*
  85.  *  Verify that Swap file exists
  86.  */
  87.  
  88. IF STREAM(swapfile,'C','QUERY EXIST') <> swapfile THEN
  89.   DO
  90.     SAY color.bad
  91.     SAY 'ERROR: ' swapfile ' not found!'
  92.     SAY color.time
  93.     EXIT
  94.   END
  95.  
  96. /*
  97.  *  Begin infinite loop to query Swap file
  98.  */
  99.  
  100. DO FOREVER
  101.  
  102. /*
  103.  *  Query Swap file for size
  104.  *
  105.  *  Based on the size of the Swap file, display the size
  106.  *  in an appropriate color.  The size ranges are subjective
  107.  *  and could be modified to better suit various users
  108.  *  requirements and characteristics.
  109.  *
  110.  *            GREEN  <   10mb swapper
  111.  *           YELLOW  <   20mb swapper
  112.  *              RED  >=  20mb swapper
  113.  */
  114.  
  115.   msg = color.time
  116.   size = STREAM(swapfile,'C','QUERY SIZE')
  117.   IF size >= 1000000 THEN
  118.     DO
  119.       size = size / 1000000.0
  120.       IF suffix = 1 THEN scale = 'M '
  121.       ELSE scale = ' '
  122.       digits = 0
  123.       SELECT
  124.         WHEN size >= 20.0 THEN  msg = msg || color.bad
  125.         WHEN FORMAT(size,,1) >= 10.0 THEN  msg = msg || color.warn
  126.         OTHERWISE
  127.           DO
  128.             msg = msg || color.ok
  129.             digits = 1
  130.           END
  131.       END
  132.     END
  133.   ELSE
  134.     DO
  135.       size = size / 1000
  136.       scale = 'K '
  137.       digits = 0
  138.       msg = msg || color.bad
  139.     END
  140.  
  141.   msg = msg || FORMAT(size,,digits)||scale
  142.  
  143. /*
  144.  *  Query Drive(s) for free space
  145.  *
  146.  *  Based on the amount of disk space remaining, display the
  147.  *  free space in an appropriate color.  The ranges are not
  148.  *  very subjective, but could be modified to better suit
  149.  *  various users requirements and characteristics.
  150.  *
  151.  *            GREEN  >=  10mb free space remaining
  152.  *           YELLOW  >    2mb free space remaining
  153.  *              RED  <=   2mb free space remaining
  154.  */
  155.  
  156.   DO n = 1 to numdrvs
  157.     swapdrv = scandrv.n
  158.     msg = msg || color.time||swapdrv
  159.  
  160.     PARSE VALUE SysDriveInfo(swapdrv) WITH drv size total label
  161.     IF size >= 1000000 THEN
  162.       DO
  163.         size = size / 1000000.0
  164.         IF suffix = 1 THEN scale = 'M '
  165.         ELSE scale = ' '
  166.         digits = 1
  167.         SELECT
  168.           WHEN size <= 2.0  THEN  msg = msg || color.bad
  169.           WHEN FORMAT(size,,1) <= 10.0 THEN  msg = msg || color.warn
  170.           OTHERWISE
  171.           DO
  172.             msg = msg || color.ok
  173.             digits = 0
  174.           END
  175.         END
  176.       END
  177.     ELSE
  178.       DO
  179.         size = size / 1000
  180.         scale = 'K '
  181.         digits = 0
  182.         msg = msg || color.bad
  183.       END
  184.  
  185.     msg = msg || FORMAT(size,,digits)||scale
  186.   END
  187.  
  188. /*
  189.  *  Current time
  190.  */
  191.  
  192.   msg = msg||color.time||' '||TIME()
  193.  
  194. /*
  195.  *  Display message and delay
  196.  */
  197.  
  198.   SAY msg
  199.   CALL SysSleep delay
  200.  
  201. END
  202.  
  203. /*
  204.  *  Break processing section
  205.  */
  206.  
  207. EndIt: SAY color.time
  208.        EXIT
  209.  
  210.