Unix Technical Forum

Can CLP output be timestamped?

This is a discussion on Can CLP output be timestamped? within the DB2 forums, part of the Database Server Software category; --> When running files containing many sql statements using the db2 command line processor, I`d like to have the output ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 05:14 AM
Carl Castrianni
 
Posts: n/a
Default Can CLP output be timestamped?

When running files containing many sql statements using the db2
command line processor, I`d like to have the output show the time that
each sql statement was executed (so I know when they ran).

Something like:
10:05:00 Select count(*) from .....
10:05:30 Select count(*) from .....

Is there a way to do this? I know db2batch can do this (with SET
TIMESTAMP) but I`d rather use db2 clp.
Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 05:14 AM
Jan M. Nelken
 
Posts: n/a
Default Re: Can CLP output be timestamped?

Carl Castrianni wrote:
> When running files containing many sql statements using the db2
> command line processor, I`d like to have the output show the time that
> each sql statement was executed (so I know when they ran).
>
> Something like:
> 10:05:00 Select count(*) from .....
> 10:05:30 Select count(*) from .....
>
> Is there a way to do this? I know db2batch can do this (with SET
> TIMESTAMP) but I`d rather use db2 clp.
> Thanks!


Can you use simply script like this:

connect to sample;
values current timestamp;
select count(*) from org;
values current timestamp;
select count(*) from staff;
values current timestamp;
connect reset;

Jan M. Nelken


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 05:14 AM
gogotank
 
Posts: n/a
Default Re: Can CLP output be timestamped?

Yes this it possible.
The most convinient way to do this (for me) is
using the pipe symbol ( | ).
You just run the script from cmdline and redirect (pipe)
its output to some program like tee, etc...

If you running windows you can use my output filter script (.vbs):
save it as .vbs file
'================================================= =========================================
'= outputfilter.vbs
'= special script to capture output from db2 command processor.
'= it can be used as a general output filter (with any console
programs)
'= USAGE (in .cmd file):
'=
'= %comspec% /c script.cmd 2>&1 ^| cscript //nologo outputfilter.vbs
/logfile:script.log
'= output will be echoed to screen and (optionally)
'= saved in script%ISODATE%.log
'================================================= =========================================
Option Explicit
Dim WshShell, StdIn, StdOut, str, outf, outfilename, fso

Set WshShell = WScript.CreateObject("WScript.Shell")

'Set sv-se locale for ISO date/time formatting, example: 2005-03-23
09:13:37
SetLocale "sv-se"

Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

set fso = CreateObject("Scripting.FileSystemObject")

outfilename = Cstr(wscript.arguments.named("logfile"))

if len(outfilename)>0 then
set outf = fso.CreateTextFile(outfilename)
else
set outf = nothing
end if

On error resume next
Do While Not StdIn.AtEndOfStream
'replace is needed to remove vbCr symbol
str = Replace(StdIn.ReadLine,vbCr,vbNullstring)
Echo str
Loop

Sub Echo(sMessage)
Dim sMsg
sMsg = Date & " " & Time & " " & sMessage
stdout.writeline sMsg
CheckError "Write to StdOut"
if not outf is nothing then
outf.writeline sMsg
CheckError "Write to output file"
end if
End Sub


Sub CheckError(sMessage)
Dim errNum,errDesc,errSource, errMessage

if err.number<>0 then
errNum = err.Number
errDesc = err.description
errSource = err.source
errMessage = "Error occured. " & sMessage & _
"#" & errNum & "(0x" & errnum & "), " & errDesc & _
", source " & errSource

on error goto 0
WshShell.LogEvent 1,errMessage
Wscript.echo errMessage
end if
End Sub

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 05:14 AM
Gert van der Kooij
 
Posts: n/a
Default Re: Can CLP output be timestamped?

In article <qj9pc1hn6h0qs6a7finea76hcihlp0lb28@4ax.com>, Carl
Castrianni (flatmountains@comcast.net) says...
> When running files containing many sql statements using the db2
> command line processor, I`d like to have the output show the time that
> each sql statement was executed (so I know when they ran).
>
> Something like:
> 10:05:00 Select count(*) from .....
> 10:05:30 Select count(*) from .....
>
> Is there a way to do this? I know db2batch can do this (with SET
> TIMESTAMP) but I`d rather use db2 clp.
> Thanks!
>


db2 select current time, count(*) from ....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 05:14 AM
Carl Castrianni
 
Posts: n/a
Default Re: Can CLP output be timestamped?

Thank you very much for the vbs script. That does what I needed.

I didn't want to have to edit all of my sql files to accomplish this.

Much thanks!


On 6 Jul 2005 23:22:07 -0700, "gogotank" <gogotank@yandex.ru> wrote:

>Yes this it possible.
>The most convinient way to do this (for me) is
>using the pipe symbol ( | ).
>You just run the script from cmdline and redirect (pipe)
>its output to some program like tee, etc...
>
>If you running windows you can use my output filter script (.vbs):
>save it as .vbs file
>'================================================ ==========================================
>'= outputfilter.vbs
>'= special script to capture output from db2 command processor.
>'= it can be used as a general output filter (with any console
>programs)
>'= USAGE (in .cmd file):
>'=
>'= %comspec% /c script.cmd 2>&1 ^| cscript //nologo outputfilter.vbs
>/logfile:script.log
>'= output will be echoed to screen and (optionally)
>'= saved in script%ISODATE%.log
>'================================================ ==========================================
>Option Explicit
>Dim WshShell, StdIn, StdOut, str, outf, outfilename, fso
>
>Set WshShell = WScript.CreateObject("WScript.Shell")
>
>'Set sv-se locale for ISO date/time formatting, example: 2005-03-23
>09:13:37
>SetLocale "sv-se"
>
>Set StdIn = WScript.StdIn
>Set StdOut = WScript.StdOut
>
>set fso = CreateObject("Scripting.FileSystemObject")
>
>outfilename = Cstr(wscript.arguments.named("logfile"))
>
>if len(outfilename)>0 then
> set outf = fso.CreateTextFile(outfilename)
>else
> set outf = nothing
>end if
>
>On error resume next
>Do While Not StdIn.AtEndOfStream
> 'replace is needed to remove vbCr symbol
> str = Replace(StdIn.ReadLine,vbCr,vbNullstring)
> Echo str
>Loop
>
>Sub Echo(sMessage)
> Dim sMsg
> sMsg = Date & " " & Time & " " & sMessage
> stdout.writeline sMsg
> CheckError "Write to StdOut"
> if not outf is nothing then
> outf.writeline sMsg
> CheckError "Write to output file"
> end if
>End Sub
>
>
>Sub CheckError(sMessage)
> Dim errNum,errDesc,errSource, errMessage
>
> if err.number<>0 then
> errNum = err.Number
> errDesc = err.description
> errSource = err.source
> errMessage = "Error occured. " & sMessage & _
> "#" & errNum & "(0x" & errnum & "), " & errDesc & _
> ", source " & errSource
>
> on error goto 0
> WshShell.LogEvent 1,errMessage
> Wscript.echo errMessage
> end if
>End Sub


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 05:14 AM
gogotank
 
Posts: n/a
Default Re: Can CLP output be timestamped?

You welcome.
Actually i found that i'm using different script.
Is much smaller and include error detection.
It is usable for interactive script execution

'db2outputfilter.vbs
Option Explicit
SetLocale "sv-se"

Dim StdIn, StdOut, str, bWasError,sMsgId

Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut

Do While Not StdIn.AtEndOfStream
'str = StdIn.ReadLine
str = Replace(StdIn.ReadLine,vbCr,vbNullstring)
if left(str,3)="SQL" then
sMsgId = Trim(Left(str,9))
if Right(sMsgId,1) = "N" then
bWasError = TRUE
MsgBox str, vbOkOnly + vbCritical, "Db2 error"
end if
end if

StdOut.WriteLine Date & " " & Time & " " & str
Loop


If bWasError then
wscript.quit 1
end if

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com