home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
db22re.zip
/
MON_DB.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-03-09
|
10KB
|
318 lines
/*
┌──────────────────────────────────────────────────────────────────┐
│ Name : mon_db.cmd │
│ Purpose : Monitor log files for FRDEMO │
│ Platform : DB2/2 │
│ Author : Jeff Fisher │
│ IBM Toronto Development Lab │
│ Disclaimer : This "sample" code is for demonstrations only, no │
│ warrenties are made or implied as to correct │
│ function. You should carefully test this code in │
│ your own environment before using it. │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
signal on syntax
signal on error
address cmd '@ECHO OFF'
call SetColor
Main:
/*
┌──────────────────────────────────────────────────────────────────┐
│ Main routine for program : run thru loop of collecting status │
│ and then freeing the resourse. │
└──────────────────────────────────────────────────────────────────┘
*/
call CollectStatus
call FreeResources
signal Main
CollectStatus:
/*
┌──────────────────────────────────────────────────────────────────┐
│ Collect the status, check and handle various types of sqlcodes. │
│ if anyone is "on" the database, then do the display. │
└──────────────────────────────────────────────────────────────────┘
*/
address cmd 'CLS'
say
step = 'Collect All Status'
call SQLDBS 'COLLECT ALL STATUS for database FRDEMO USING :SSTAT'
call CheckSafeSQLcode
if SafeSQLcode = 'Y' then signal CollectStatus
else
if SafeSQLcode = 'N' then signal ErrorSQL
if SSTAT.10 > 0 then
do
dbname = SSTAT.12
call UserStat
end
else
do
say
say c.yellow '*** NO USERS AT THIS TIME ***'
say c.grey
pause
end
return
FreeResources:
/*
┌──────────────────────────────────────────────────────────────────┐
│ must free resources within the engine! │
└──────────────────────────────────────────────────────────────────┘
*/
step = 'Free Status Resources'
call SQLDBS 'FREE STATUS RESOURCES'
call CheckSafeSQLcode
if SafeSQLcode = 'Y' then signal FreeResources
else
if SafeSQLcode = 'N' then signal ErrorSQL
return
UserStat:
/*
┌──────────────────────────────────────────────────────────────────┐
│ This loop is for individual users. The program will work for │
│ as many users as are on the system. │
└──────────────────────────────────────────────────────────────────┘
*/
step = 'Get User Status loop'
tod = time()
CALL SQLDBS 'GET USER STATUS FOR DATABASE' dbname 'USING :USTAT'
if SQLCA.SQLCODE \= 0 then signal ErrorSQL
do i=1 to USTAT.0
address cmd 'CLS'
say
say
if sstat.10 = 1 then
say c.yellow 'FRDEMO has'c.itmagenta sstat.10 c.yellow'user at' tod
else
say c.yellow 'FRDEMO has'c.itmagenta sstat.10 c.yellow'users at' tod
say
if ustat.i.8 = '0' then ustat.i.8 = '00000'
say c.itmagenta '#'i c.itcyan 'Authid:'c.itgreen USTAT.i.6 c.itcyan 'Auth lvl:'c.itgreen USTAT.i.8
checkvar = VERIFY(USTAT.i.7,' ')
if checkvar = 1 then USTAT.i.7 = '(local)'
say c.itcyan ' Node :'c.itgreen USTAT.i.7
say
say c.yellow 'Since START USING: '
say c.itcyan ' UOWs :'c.itgreen USTAT.i.1
say c.itcyan ' SQL transactions :'c.itgreen USTAT.i.2
say c.itcyan ' Elapsed time (secs) :'c.itgreen USTAT.i.4
say
say c.yellow 'Current UOW:'
say c.itcyan ' SQL transactions :'c.itgreen USTAT.i.3
say c.itcyan ' Elapsed time (secs) :'c.itgreen USTAT.i.5
call CalcTPS
say c.itcyan ' TPS rate :'c.itgreen TPS
if ustat.i.9 = 'S' then ustat.i.9 = 'Started'
if ustat.i.9 = 'R' then ustat.i.9 = 'Open, no changes'
if ustat.i.9 = 'C' then ustat.i.9 = 'Changed DB'
say c.itcyan ' Status :'c.itgreen USTAT.i.9
if ustat.i.10 = 'N' then
do
ustat.i.10 = 'NO'
say c.itcyan ' Waiting for LOCK? :'c.itgreen USTAT.i.10
end
else
do
ustat.i.10 = 'YES'
say c.itcyan ' Waiting for LOCK? :'c.itred USTAT.i.10 '<---'
end
say
say c.normal
pause
end
return 0
CalcTPS:
/*
┌──────────────────────────────────────────────────────────────────┐
│ Calculation of the TPS (within that UOW) │
└──────────────────────────────────────────────────────────────────┘
*/
tps = 0
if ustat.i.3 = 0 then
do
tps = 0
return
end
if ustat.i.5 = 0 then
do
tps = 0
return
end
tps = ustat.i.3 / ustat.i.5
return
CheckSafeSQLcode:
/*
┌──────────────────────────────────────────────────────────────────┐
│ Check for a "safe" sqlcode, which we will handle, versus a │
│ fatal sqlcode. If there are further "safe" codes, they must │
│ be hard coded in here along with their message. │
└──────────────────────────────────────────────────────────────────┘
*/
SafeSQLcode = 'N'
SELECT
WHEN SQLCA.SQLCODE = 0 then
do
SafeSQLcode = '0'
end
WHEN SQLCA.SQLCODE = -1033 then
do
SafeSQLcode = 'Y'
say
say c.yellow '*** Database cannot be opened for status ***'
say c.yellow '*** Database directory being updated ***'
end
WHEN SQLCA.SQLCODE = -1035 then
do
SafeSQLcode = 'Y'
say
say c.yellow '*** Database cannot be opened for status ***'
say c.yellow '*** Another user has exclusive use of it ***'
end
WHEN SQLCA.SQLCODE = -1119 then
do
SafeSQLcode = 'Y'
say
say c.yellow '*** A Database Restore is in progress ***'
end
WHEN SQLCA.SQLCODE = -1117 then
do
SafeSQLcode = 'Y'
say
say c.yellow '*** A Roll Forward is pending ***'
end
OTHERWISE SafeSQLcode = 'N'
END
SELECT
WHEN SafeSQLcode = 'Y' then
do
say c.yellow ' Press <enter> when the '
say c.yellow ' function is complete '
say c.yellow ' in order to continue... '
say c.grey
pause
end
OTHERWISE NOP
END
return
EndProg:
/*
┌──────────────────────────────────────────────────────────────────┐
│ end program, reset colors. │
└──────────────────────────────────────────────────────────────────┘
*/
say c.normal
address cmd 'CLS'
'exit'
Error:
/*
┌──────────────────────────────────────────────────────────────────┐
│ error │
└──────────────────────────────────────────────────────────────────┘
*/
call beep 220,1000
say c.itred
say ' >>> Rexx has returned a signal on error'
say ' abending step = ' step
say ' source line = ' sourceline(sigl)
say
pause
signal EndProg
Syntax:
/*
┌──────────────────────────────────────────────────────────────────┐
│ rexx syntax bug │
└──────────────────────────────────────────────────────────────────┘
*/
call beep 220,1000
say c.itred
say ' >>> Rexx has returned a signal on syntax'
say ' abending step = ' step
say ' source line = ' sourceline(sigl)
say
pause
signal EndProg
ErrorSQL:
/*
┌──────────────────────────────────────────────────────────────────┐
│ sql error handling routine │
└──────────────────────────────────────────────────────────────────┘
*/
call beep 220,1000
say c.itred
say ' >>> SQL has returned a fatal condition code'
say ' abending step = ' step
say ' SQLCODE = ' SQLCA.SQLCODE
say ' MSG = ' SQLMSG
say
pause
signal EndProg
SetColor:
/*
┌──────────────────────────────────────────────────────────────────┐
│ set colors with ansi escape chars │
└──────────────────────────────────────────────────────────────────┘
*/
ansii.esc = '1B'x
c.normal = ansii.esc || '[0m'
c.highlite = ansii.esc || '[1m'
c.blackback = ansii.esc || '[40m'
c.grey = c.normal || ansii.esc || '[37m'
c.itred = c.highlite || ansii.esc || '[31m'
c.itnormal = c.highlite || ansii.esc || '[32m'
c.yellow = c.highlite || ansii.esc || '[33m'
c.itgreen = c.highlite || ansii.esc || '[32m'
c.itblue = c.highlite || ansii.esc || '[34m'
c.itmagenta = c.highlite || ansii.esc || '[35m'
c.itcyan = c.highlite || ansii.esc || '[36m'
c.white = c.highlite || ansii.esc || '[37m'
c.std = c.normal || c.itcyan || c.blackback
c.reset = c.normal || c.grey || c.blackback
return 0