home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
db22fr.zip
/
MON_DB.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-05-12
|
13KB
|
412 lines
/*
┌──────────────────────────────────────────────────────────────────┐
│ Name : mon_db.cmd │
│ Purpose : Monitor log files for a selected database │
│ Platform : DB2/2 and OS/2 2.1 │
│ Author : Jeff Fisher │
│ Copyright IBM Corporation 1993 │
│ IBM Toronto Development Lab │
│ │
│ Written : 08/31/91 │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
signal on syntax
signal on error
call BeginProg
MainControl:
drivemap = SysDriveMap(C,LOCAL)
occurance = 0
drives = words(drivemap)
do i = 1 to drives
parse var drivemap drive.i drivemap
db_drive.i = left(strip(drive.i), 1)
call DirScan db_drive.i
end
if scan_flag = 'Y' then
do
step = 'close database directory'
call SQLDBS 'CLOSE DATABASE DIRECTORY :scanvar.1'
end
SelectMonitorDBMenu:
call SysCls
say
say c.itcyan '******************************************'
say c.yellow ' Choose a Database to monitor: '
do z=1 to occurance
say c.yellow ' 'z ' ' dbname.z
end
say c.yellow ' Or, choose an option: '
say c.yellow ' R (refresh menu) '
say c.yellow ' X (to exit) '
say c.itcyan '******************************************'
row = 3
col = 2
pos = SysCurPos(row,col)
SelectDB = SysGetKey('NOECHO')
if SelectDB = 'R' | SelectDB = 'r' then signal MainControl
if SelectDB = 'X' | SelectDB = 'x' then signal EndProg
say SelectDB
call MonitorMain dbname.SelectDB
signal MainControl
DirScan:
arg scandrive
step = 'open database directory'
call SQLDBS 'OPEN DATABASE DIRECTORY ON' scandrive 'using :scanvar'
if SQLCA.SQLCODE = 1057 then return
if SQLCA.SQLCODE = -1031 then return
if SQLCA.SQLCODE \= 0 then signal ErrorSQL
scan_flag = 'Y'
do loop1 = 1 to scanvar.2
step = 'get database directory entry'
call SQLDBS 'GET DATABASE DIRECTORY ENTRY :scanvar.1 USING :entry'
if SQLCA.SQLCODE \= 0 then signal ErrorSQL
occurance = occurance + 1
dbname.occurance = entry.1
end
step = 'close database directory'
call SQLDBS 'CLOSE DATABASE DIRECTORY :scanvar.1'
if SQLCA.SQLCODE \= 0 then signal ErrorSQL
return
MonitorMain:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
arg MonitorDB
EndSession = 'N'
call CollectStatus
call FreeResources
if EndSession = 'Y' then return
else signal MonitorMain
CollectStatus:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
call SysCls
step = 'Collect All Status'
call SQLDBS 'COLLECT ALL STATUS for database' MonitorDB 'USING :SSTAT'
call CheckSafeSQLcode
if SafeSQLcode = 'Y' then signal CollectStatus
else
if SafeSQLcode = 'N' then signal ErrorSQL
if SSTAT.10 > 0 then call UserStat
else
do
say
say c.yellow MonitorDB ': NO USERS AT THIS TIME '
say c.grey
say c.itblue '<enter> to continue; <X> to end'
nullinput = SysGetKey('NOECHO')
if nullinput = 'X' | nullinput = 'x' then EndSession = 'Y'
end
return
UserStat:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
step = 'Get User Status loop'
tod = time()
CALL SQLDBS 'GET USER STATUS FOR DATABASE' MonitorDB 'USING :USTAT'
if SQLCA.SQLCODE \= 0 then signal ErrorSQL
do y=1 to USTAT.0
row = 3
col = 2
pos = SysCurPos(row,col)
if sstat.10 = 1 then
say c.yellow MonitorDB 'has'c.itmagenta sstat.10 c.yellow'user at' tod
else
say c.yellow MonitorDB 'has'c.itmagenta sstat.10 c.yellow'users at' tod
say
if ustat.i.8 = '0' then ustat.y.8 = '00000'
say c.itmagenta '#'y c.itcyan 'Authid:'c.itgreen USTAT.y.6 c.itcyan 'Auth lvl:'c.itgreen USTAT.y.8
checkvar = VERIFY(USTAT.y.7,' ')
if checkvar = 1 then USTAT.y.7 = '(local)'
say c.itcyan ' Node :'c.itgreen USTAT.y.7
say
say c.yellow 'Since CONNECT:'
say c.itcyan ' UOWs :'c.itgreen USTAT.y.1
say c.itcyan ' SQL transactions :'c.itgreen USTAT.y.2
say c.itcyan ' Elapsed time (secs) :'c.itgreen USTAT.y.4
say
say c.yellow 'Current UOW:'
say c.itcyan ' SQL transactions :'c.itgreen USTAT.y.3
say c.itcyan ' Elapsed time (secs) :'c.itgreen USTAT.y.5
call CalcTPS
say c.itcyan ' TPS rate :'c.itgreen TPS
if ustat.y.9 = 'S' then ustat.y.9 = 'Started'
if ustat.y.9 = 'R' then ustat.y.9 = 'Open, no changes'
if ustat.y.9 = 'C' then ustat.y.9 = 'Changed DB'
say c.itcyan ' Status :'c.itgreen USTAT.y.9
if ustat.y.10 = 'N' then
do
ustat.y.10 = 'NO'
say c.itcyan ' Waiting for LOCK? :'c.itgreen USTAT.y.10
end
else
do
ustat.y.10 = 'YES'
say c.itcyan ' Waiting for LOCK? :'c.itred USTAT.y.10 '<---'
end
say c.normal
say c.itblue '<enter> to continue; <X> to end'
nullinput = SysGetKey('NOECHO')
if nullinput = 'X' | nullinput = 'x' then EndSession = 'Y'
end
return 0
CalcTPS:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
tps = 0
SELECT
WHEN ustat.y.3 = 0 then tps = 0
WHEN ustat.y.5 = 0 then tps = 0
OTHERWISE tps = ustat.y.3 / ustat.y.5
END
return
CheckSafeSQLcode:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
SafeSQLcode = 'N'
SELECT
WHEN SQLCA.SQLCODE = 0 then
do
SafeSQLcode = '0'
end
WHEN SQLCA.SQLCODE = -1013 then
do
SafeSQLcode = 'Y'
say
say c.yellow '*** Database FRDEMO does not exist ***'
say c.yellow '*** create the database and try again ***'
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 '
say c.yellow ' ready in order to '
say c.yellow ' continue execution..... '
say c.grey
pause
end
OTHERWISE NOP
END
return
FreeResources:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
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
BeginProg:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
call RxFuncAdd 'SQLDBS','SQLAR','SQLDBS'
call RxFuncAdd 'SQLEXEC','SQLAR','SQLEXEC'
call SysLoadFuncs
address cmd '@ECHO OFF'
call SysCls
call SetColor
return
EndProg:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
say c.normal
call SysCls
exit
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:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
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:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
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:
/*
┌──────────────────────────────────────────────────────────────────┐
│ │
│ │
└──────────────────────────────────────────────────────────────────┘
*/
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