home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / db22fr.zip / MON_DB.CMD < prev    next >
OS/2 REXX Batch file  |  1993-05-12  |  13KB  |  412 lines

  1. /*
  2.  ┌──────────────────────────────────────────────────────────────────┐
  3.  │  Name       : mon_db.cmd                                         │
  4.  │  Purpose    : Monitor log files for a selected database          │
  5.  │  Platform   : DB2/2 and OS/2 2.1                                 │
  6.  │  Author     : Jeff Fisher                                        │
  7.  │               Copyright IBM Corporation 1993                     │
  8.  │               IBM Toronto Development Lab                        │
  9.  │                                                                  │
  10.  │  Written    : 08/31/91                                           │
  11.  │                                                                  │
  12.  └──────────────────────────────────────────────────────────────────┘
  13. */
  14.  
  15. signal on syntax
  16. signal on error
  17.  
  18. call BeginProg
  19.  
  20. MainControl:
  21.     drivemap = SysDriveMap(C,LOCAL)
  22.     occurance = 0
  23.     drives = words(drivemap)
  24.  
  25.     do i = 1 to drives
  26.       parse var drivemap drive.i drivemap
  27.       db_drive.i = left(strip(drive.i), 1)
  28.       call DirScan db_drive.i
  29.     end
  30.  
  31.     if scan_flag = 'Y' then
  32.         do
  33.             step = 'close database directory'
  34.             call SQLDBS 'CLOSE DATABASE DIRECTORY :scanvar.1'
  35.         end
  36.  
  37. SelectMonitorDBMenu:
  38.     call SysCls
  39.     say
  40.     say c.itcyan '******************************************'
  41.     say c.yellow ' Choose a Database to monitor:            '
  42.     do z=1 to occurance
  43.         say c.yellow '   'z '  ' dbname.z
  44.     end
  45.     say c.yellow ' Or, choose an option:                    '
  46.     say c.yellow '   R    (refresh menu)                    '
  47.     say c.yellow '   X    (to exit)                         '
  48.     say c.itcyan '******************************************'
  49.  
  50.     row = 3
  51.     col = 2
  52.     pos = SysCurPos(row,col)
  53.     SelectDB = SysGetKey('NOECHO')
  54.  
  55.     if SelectDB = 'R' | SelectDB = 'r' then signal MainControl
  56.     if SelectDB = 'X' | SelectDB = 'x' then signal EndProg
  57.  
  58.     say SelectDB
  59.     call MonitorMain dbname.SelectDB
  60.  
  61.     signal MainControl
  62.  
  63.  
  64. DirScan:
  65.     arg scandrive
  66.     step = 'open database directory'
  67.     call SQLDBS 'OPEN DATABASE DIRECTORY ON' scandrive 'using :scanvar'
  68.     if SQLCA.SQLCODE = 1057 then return
  69.     if SQLCA.SQLCODE = -1031 then return
  70.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  71.  
  72.     scan_flag = 'Y'
  73.  
  74.     do loop1 = 1 to scanvar.2
  75.       step = 'get database directory entry'
  76.       call SQLDBS 'GET DATABASE DIRECTORY ENTRY :scanvar.1 USING :entry'
  77.       if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  78.       occurance = occurance + 1
  79.       dbname.occurance = entry.1
  80.     end
  81.  
  82.     step = 'close database directory'
  83.     call SQLDBS 'CLOSE DATABASE DIRECTORY :scanvar.1'
  84.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  85.  
  86.     return
  87.  
  88.  
  89. MonitorMain:
  90. /*
  91.  ┌──────────────────────────────────────────────────────────────────┐
  92.  │                                                                  │
  93.  │                                                                  │
  94.  └──────────────────────────────────────────────────────────────────┘
  95. */
  96.     arg MonitorDB
  97.  
  98.     EndSession = 'N'
  99.  
  100.     call CollectStatus
  101.  
  102.     call FreeResources
  103.  
  104.     if EndSession = 'Y' then return
  105.     else signal MonitorMain
  106.  
  107.  
  108. CollectStatus:
  109. /*
  110.  ┌──────────────────────────────────────────────────────────────────┐
  111.  │                                                                  │
  112.  │                                                                  │
  113.  └──────────────────────────────────────────────────────────────────┘
  114. */
  115.     call SysCls
  116.  
  117.     step = 'Collect All Status'
  118.     call SQLDBS 'COLLECT ALL STATUS for database' MonitorDB 'USING :SSTAT'
  119.  
  120.     call CheckSafeSQLcode
  121.     if SafeSQLcode = 'Y' then signal CollectStatus
  122.     else
  123.         if SafeSQLcode = 'N' then signal ErrorSQL
  124.  
  125.     if SSTAT.10 > 0 then call UserStat
  126.     else
  127.         do
  128.             say
  129.             say c.yellow MonitorDB ': NO USERS AT THIS TIME '
  130.             say c.grey
  131.             say c.itblue '<enter> to continue; <X> to end'
  132.             nullinput = SysGetKey('NOECHO')
  133.             if nullinput = 'X' | nullinput = 'x' then EndSession = 'Y'
  134.         end
  135.  
  136.     return
  137.  
  138.  
  139. UserStat:
  140. /*
  141.  ┌──────────────────────────────────────────────────────────────────┐
  142.  │                                                                  │
  143.  │                                                                  │
  144.  └──────────────────────────────────────────────────────────────────┘
  145. */
  146.     step = 'Get User Status loop'
  147.     tod = time()
  148.     CALL SQLDBS 'GET USER STATUS FOR DATABASE' MonitorDB 'USING :USTAT'
  149.     if SQLCA.SQLCODE \= 0 then signal ErrorSQL
  150.  
  151.     do y=1 to USTAT.0
  152.       row = 3
  153.       col = 2
  154.       pos = SysCurPos(row,col)
  155.  
  156.       if sstat.10 = 1 then
  157.         say c.yellow MonitorDB 'has'c.itmagenta sstat.10 c.yellow'user at' tod
  158.       else
  159.         say c.yellow MonitorDB 'has'c.itmagenta sstat.10 c.yellow'users at' tod
  160.       say
  161.  
  162.       if ustat.i.8 = '0' then ustat.y.8 = '00000'
  163.       say c.itmagenta '#'y c.itcyan 'Authid:'c.itgreen USTAT.y.6 c.itcyan 'Auth lvl:'c.itgreen USTAT.y.8
  164.  
  165.       checkvar = VERIFY(USTAT.y.7,' ')
  166.       if checkvar = 1 then USTAT.y.7 = '(local)'
  167.       say c.itcyan '    Node  :'c.itgreen USTAT.y.7
  168.  
  169.       say
  170.       say c.yellow   'Since CONNECT:'
  171.       say c.itcyan   '  UOWs                :'c.itgreen USTAT.y.1
  172.       say c.itcyan   '  SQL transactions    :'c.itgreen USTAT.y.2
  173.       say c.itcyan   '  Elapsed time (secs) :'c.itgreen USTAT.y.4
  174.       say
  175.       say c.yellow   'Current UOW:'
  176.       say c.itcyan   '  SQL transactions    :'c.itgreen USTAT.y.3
  177.       say c.itcyan   '  Elapsed time (secs) :'c.itgreen USTAT.y.5
  178.       call CalcTPS
  179.       say c.itcyan   '  TPS rate            :'c.itgreen TPS
  180.       if ustat.y.9 = 'S' then ustat.y.9 = 'Started'
  181.       if ustat.y.9 = 'R' then ustat.y.9 = 'Open, no changes'
  182.       if ustat.y.9 = 'C' then ustat.y.9 = 'Changed DB'
  183.         say c.itcyan '  Status              :'c.itgreen USTAT.y.9
  184.  
  185.       if ustat.y.10 = 'N' then
  186.         do
  187.           ustat.y.10 = 'NO'
  188.           say c.itcyan '  Waiting for LOCK?   :'c.itgreen USTAT.y.10
  189.         end
  190.       else
  191.         do
  192.           ustat.y.10 = 'YES'
  193.           say c.itcyan '  Waiting for LOCK?   :'c.itred   USTAT.y.10 '<---'
  194.         end
  195.  
  196.       say c.normal
  197.       say c.itblue '<enter> to continue; <X> to end'
  198.       nullinput = SysGetKey('NOECHO')
  199.       if nullinput = 'X' | nullinput = 'x' then EndSession = 'Y'
  200.     end
  201.     return 0
  202.  
  203.  
  204. CalcTPS:
  205. /*
  206.  ┌──────────────────────────────────────────────────────────────────┐
  207.  │                                                                  │
  208.  │                                                                  │
  209.  └──────────────────────────────────────────────────────────────────┘
  210. */
  211.     tps = 0
  212.  
  213.     SELECT
  214.         WHEN ustat.y.3 = 0  then tps = 0
  215.         WHEN ustat.y.5 = 0  then tps = 0
  216.         OTHERWISE           tps = ustat.y.3 / ustat.y.5
  217.     END
  218.  
  219.     return
  220.  
  221.  
  222. CheckSafeSQLcode:
  223. /*
  224.  ┌──────────────────────────────────────────────────────────────────┐
  225.  │                                                                  │
  226.  │                                                                  │
  227.  └──────────────────────────────────────────────────────────────────┘
  228. */
  229.     SafeSQLcode = 'N'
  230.  
  231.     SELECT
  232.         WHEN SQLCA.SQLCODE = 0 then
  233.           do
  234.             SafeSQLcode = '0'
  235.           end
  236.         WHEN SQLCA.SQLCODE = -1013 then
  237.           do
  238.             SafeSQLcode = 'Y'
  239.             say
  240.             say c.yellow '*** Database FRDEMO does not exist       ***'
  241.             say c.yellow '*** create the database and try again    ***'
  242.           end
  243.         WHEN SQLCA.SQLCODE = -1033 then
  244.           do
  245.             SafeSQLcode = 'Y'
  246.             say
  247.             say c.yellow '*** Database cannot be opened for status ***'
  248.             say c.yellow '*** Database directory being updated     ***'
  249.           end
  250.         WHEN SQLCA.SQLCODE = -1035 then
  251.           do
  252.             SafeSQLcode = 'Y'
  253.             say
  254.             say c.yellow '*** Database cannot be opened for status ***'
  255.             say c.yellow '*** Another user has exclusive use of it ***'
  256.           end
  257.         WHEN SQLCA.SQLCODE = -1119 then
  258.           do
  259.             SafeSQLcode = 'Y'
  260.             say
  261.             say c.yellow '*** A Database Restore is in progress ***'
  262.           end
  263.         WHEN SQLCA.SQLCODE = -1117 then
  264.           do
  265.             SafeSQLcode = 'Y'
  266.             say
  267.             say c.yellow '*** A Roll Forward is pending ***'
  268.           end
  269.         OTHERWISE SafeSQLcode = 'N'
  270.     END
  271.  
  272.     SELECT
  273.         WHEN SafeSQLcode = 'Y' then
  274.           do
  275.             say c.yellow '    Press <enter> when       '
  276.             say c.yellow '    ready in order to        '
  277.             say c.yellow '    continue execution.....  '
  278.             say c.grey
  279.             pause
  280.           end
  281.         OTHERWISE NOP
  282.     END
  283.  
  284.     return
  285.  
  286.  
  287. FreeResources:
  288. /*
  289.  ┌──────────────────────────────────────────────────────────────────┐
  290.  │                                                                  │
  291.  │                                                                  │
  292.  └──────────────────────────────────────────────────────────────────┘
  293. */
  294.     step = 'Free Status Resources'
  295.     call SQLDBS 'FREE STATUS RESOURCES'
  296.  
  297.     call CheckSafeSQLcode
  298.     if SafeSQLcode = 'Y' then signal FreeResources
  299.     else
  300.         if SafeSQLcode = 'N' then signal ErrorSQL
  301.  
  302.     return
  303.  
  304.  
  305. BeginProg:
  306. /*
  307.  ┌──────────────────────────────────────────────────────────────────┐
  308.  │                                                                  │
  309.  │                                                                  │
  310.  └──────────────────────────────────────────────────────────────────┘
  311. */
  312.     call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  313.     call RxFuncAdd 'SQLDBS','SQLAR','SQLDBS'
  314.     call RxFuncAdd 'SQLEXEC','SQLAR','SQLEXEC'
  315.     call SysLoadFuncs
  316.     address cmd '@ECHO OFF'
  317.     call SysCls
  318.     call SetColor
  319.  
  320.     return
  321.  
  322.  
  323. EndProg:
  324. /*
  325.  ┌──────────────────────────────────────────────────────────────────┐
  326.  │                                                                  │
  327.  │                                                                  │
  328.  └──────────────────────────────────────────────────────────────────┘
  329. */
  330.     say c.normal
  331.  
  332.     call SysCls
  333.  
  334.     exit
  335.  
  336.  
  337. Error:
  338. /*
  339.  ┌──────────────────────────────────────────────────────────────────┐
  340.  │                                                                  │
  341.  │                                                                  │
  342.  └──────────────────────────────────────────────────────────────────┘
  343. */
  344.     call beep 220,1000
  345.     say c.itred
  346.     say '        >>>  Rexx has returned a signal on error'
  347.     say '             abending step = ' step
  348.     say '             source line   = ' sourceline(sigl)
  349.     say
  350.     pause
  351.     signal EndProg
  352.  
  353.  
  354. Syntax:
  355. /*
  356.  ┌──────────────────────────────────────────────────────────────────┐
  357.  │                                                                  │
  358.  │                                                                  │
  359.  └──────────────────────────────────────────────────────────────────┘
  360. */
  361.     call beep 220,1000
  362.     say c.itred
  363.     say '        >>>  Rexx has returned a signal on syntax'
  364.     say '             abending step = ' step
  365.     say '             source line   = ' sourceline(sigl)
  366.     say
  367.     pause
  368.     signal EndProg
  369.  
  370.  
  371. ErrorSQL:
  372. /*
  373.  ┌──────────────────────────────────────────────────────────────────┐
  374.  │                                                                  │
  375.  │                                                                  │
  376.  └──────────────────────────────────────────────────────────────────┘
  377. */
  378.     call beep 220,1000
  379.     say c.itred
  380.     say '        >>>  SQL has returned a fatal condition code'
  381.     say '             abending step = ' step
  382.     say '             SQLCODE       = ' SQLCA.SQLCODE
  383.     say '             MSG           = ' SQLMSG
  384.     say
  385.     pause
  386.     signal EndProg
  387.  
  388.  
  389. SetColor:
  390. /*
  391.  ┌──────────────────────────────────────────────────────────────────┐
  392.  │                                                                  │
  393.  │                                                                  │
  394.  └──────────────────────────────────────────────────────────────────┘
  395. */
  396.     ansii.esc      = '1B'x
  397.     c.normal       = ansii.esc || '[0m'
  398.     c.highlite     = ansii.esc || '[1m'
  399.     c.blackback    = ansii.esc || '[40m'
  400.     c.grey         = c.normal || ansii.esc || '[37m'
  401.     c.itred        = c.highlite || ansii.esc || '[31m'
  402.     c.itnormal     = c.highlite || ansii.esc || '[32m'
  403.     c.yellow       = c.highlite || ansii.esc || '[33m'
  404.     c.itgreen      = c.highlite || ansii.esc || '[32m'
  405.     c.itblue       = c.highlite || ansii.esc || '[34m'
  406.     c.itmagenta    = c.highlite || ansii.esc || '[35m'
  407.     c.itcyan       = c.highlite || ansii.esc || '[36m'
  408.     c.white        = c.highlite || ansii.esc || '[37m'
  409.     c.std          = c.normal || c.itcyan || c.blackback
  410.     c.reset        = c.normal || c.grey || c.blackback
  411.     return 0
  412.