473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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!
Nov 12 '05 #1
5 2663
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
Nov 12 '05 #2
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

Nov 12 '05 #3
In article <qj********************************@4ax.com>, Carl
Castrianni (fl***********@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 ....
Nov 12 '05 #4
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" <go******@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


Nov 12 '05 #5
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

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
3
by: edgekaos | last post by:
Is method 2 valid? Method 1: wstring input = L"STRING"; wstring output = input; transform(output.begin(), output.end(), output.begin(), towupper); Method 2: wstring input = L"STRING";...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
24
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
0
by: newbie | last post by:
i'm a newbie of c language. can anyone help me to implement the code so that I can get the ciphertext from the output. thanks. #ifndef _3DES_H #define _3DES_H #ifndef uint8 #define uint8 ...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
3
by: MatsL | last post by:
Hi, This is seriously driving me crazy, could anyone explain to me why neither of these doesn't produce XHTML compliant output (it is being called in Render() btw): output.WriteLine("<img...
3
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include...
2
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.