| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |
|

01-26-10, 13:20
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
DB2 Maintenance Batch...
|
|
Good afternoon everyone,
I am trying to create a very basic DB2 batch file that will connect to a specific database and then issue the REORGCHK command.
I started off with:
db2cmd DB2 connect to <database> user <username> using <password>
*** the above command in the batch file gets me connected to that database ***
Then i issue the other second part which is to REORGCHK the tables
db2 reorgchk update statistics on table all > (output.txt path)
*** At this point manually ran it would work but via the batch file it just sits at the login successful window***
Not sure if anyone has accomplished this or how are other DB2 admin accomplishing this, so that it is automatically and not manually.
Thank you in advance for all of your assistance,
Mit
|
|

01-26-10, 13:28
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
What is your DB2 version and OS? Can you post your entire "DB2 batch" file?
Andy
|
|

01-26-10, 13:33
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
|
|
This is running on a windows server 2003 and with DB Enterprise edition.
The batch file that i currently have is something like.
@echo off
Rem Connect to database
db2cmd DB2 connect to <database> user <username> using <password>
db2 reorgchk update statistics on table all > (output.txt path)
pause
But the second command where i am telling it to run the reorgchk never runs.
|
|

01-26-10, 13:40
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
1. Look at the correct db2cmd invokation in the manual. The way you are trying to do it, db2cmd never returns.
2. Even if it does, the connection you establish there will be closed, because db2cmd creates a separate shell.
|
|

01-26-10, 13:40
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Do it this way:
Put all of your DB2 statements is a DB2 script like this:
connect to <database> user <username> using <password>;
reorgchk update statistics on table all
Then you batch would be:
db2cmd DB2 -z output.txt -svf <DB2 script filename>
Andy
|
|

01-26-10, 13:43
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
|
|

01-26-10, 14:11
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
Ok so this is what i have for a batch file since i am currently running it from the desktop.
c:
cd \Program Files\IBM\SQLLIB\BIN
db2cmd db2setcp "%1 %2 %3 %4 %5 %6 %7 %8 %9"
db2cmd db2 connect to <database name> user <username> using <password>
====to this point the batch file runs and connects to the DB ===
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"
==== above is the command line that i can not seem to get working ===
Do i need to write the above commands on a different file extension other than .bat?
How can i get it to work?
|
|

01-26-10, 14:16
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Your problem is that db2cmd spawns off the process so what happens next is unrelated. Look at the link that Nick supplied.
Andy
|
|

01-26-10, 14:50
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
Hi Andy,
So how should i write this batch file so that db2cmd does not spawn off?
I checked the above link and added the code line;
@echo off
rem If we're not called from DB2CLP, call ourselves again
if "%DB2CLP%" == "" db2cmd /c /i /w %0 %* & goto :eof
c:
cd \Program Files\IBM\SQLLIB\BIN
db2cmd db2setcp "%1 %2 %3 %4 %5 %6 %7 %8 %9"
db2cmd db2 connect to <database name> user <username> using <password>
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"
And nothing happens.
How should i be writting this batch file?
|
|

01-26-10, 14:57
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Based on the link, it should look like:
Code:
@echo off
c:
cd \Program Files\IBM\SQLLIB\BIN
rem If we're not called from DB2CLP, call ourselves again
if "%DB2CLP%" == "" db2cmd /c /i /w %0 %* & goto :eof
db2 connect to <database name> user <username> using <password>
db2 reorgchk update statistics on table all > "c:\Program Files\IBM\Logs\reorgchk.txt"
Andy
|
|

01-26-10, 15:08
|
|
Registered User
|
|
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
|
|
He told you several posts ago to remove the db2cmd from your script and then use db2cmd when executing the script.
Dave
|
|

01-26-10, 15:08
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
Once i run the above batch, i get a very quick message on the screen and disappears.
'c:\Documents' is not recognized as an internal or external command.
Any ideas?
|
|

01-26-10, 15:13
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
Quote:
Originally Posted by mitsubishi3000gt
Any ideas?
|
Yes, I've got one. Read dos scripits for db2 again.
|
|

01-26-10, 15:13
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Open the "Command Prompt" window and try to execute from there and see what you get. Also try from the "DB2 Command Window"
Andy
|
|

01-26-10, 15:19
|
|
Registered User
|
|
Join Date: Jan 2010
Posts: 8
|
|
Hi Andy,
Is there a way to use DB2 command window right from the start within a batch file. Because that is how i have been doing the maintenance on it, via the DB2 command window one command at it time.
Please advise and if there is anyone who is already doing what i am trying to accomplish please share the code.
Thank you,
Mit
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|