Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Join Date
    Jan 2010
    Posts
    8

    Question Unanswered: 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

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    What is your DB2 version and OS? Can you post your entire "DB2 batch" file?

    Andy

  3. #3
    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    You may want to check out this thread: http://www.dbforums.com/db2/1615385-...ipits-db2.html
    ---
    "It does not work" is not a valid problem statement.

  7. #7
    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 "&#37;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?

  8. #8
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Your problem is that db2cmd spawns off the process so what happens next is unrelated. Look at the link that Nick supplied.

    Andy

  9. #9
    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 "&#37;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?

  10. #10
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  11. #11
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    He told you several posts ago to remove the db2cmd from your script and then use db2cmd when executing the script.
    Dave

  12. #12
    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?

  13. #13
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by mitsubishi3000gt View Post

    Any ideas?
    Yes, I've got one. Read http://www.dbforums.com/db2/1615385-...ipits-db2.html again.
    ---
    "It does not work" is not a valid problem statement.

  14. #14
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Open the "Command Prompt" window and try to execute from there and see what you get. Also try from the "DB2 Command Window"

    Andy

  15. #15
    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •