Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2014
    Posts
    20

    Exclamation Unanswered: Unable to connect to database via script using cron jobs

    Hi,

    I have DB2 database installed on Linux machine with Version 9.7.0 and product DB2 Enterprise Server Edition.

    I wrote a simple script to gather the tablespace stats.

    #!/bin/sh
    date
    $HOME/sqllib/bin/db2 connect to maxdb71 user XXXXXX using XXxXX>/scripts/db2tablespace.txt
    sleep 5
    $HOME/sqllib/bin/db2 LIST TABLESPACES SHOW DETAIL >> /scripts/db2tablespace.txt
    cat /scripts/db2tablespace.txt | mail -s "Db2_Health_Check" XXXXX@XxxX.xom
    db2 "connect reset"


    While executing manually the script is working fine but the same is not working while scheduled in cron-tab.

    The error given as:

    SQL1031N The database directory cannot be found on the indicated file system.
    SQLSTATE=58031
    SQL1024N A database connection does not exist. SQLSTATE=08003


    Kindly help in this scenario... Thanks in advance...

  2. #2
    Join Date
    May 2010
    Location
    India
    Posts
    84
    Provided Answers: 2
    Add following command after "#!/bin/sh" and try

    source <user home directory>/.bash_profile

  3. #3
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    Whenever you script on Linux or Unix with DB2 you should always dot in the db2profile for the relevant DB2 instance.
    This will allow your scripts to work either from the shell , or from a crontab of any account .

    For example, this line below will run the db2profile for the DB2-instance called db2inst1

    . ~db2inst1/sqllib/db2profile

    Additionally if you are wise you will always have error checking in your scripts (your example does not have any).

  4. #4
    Join Date
    Jan 2014
    Posts
    20
    Thanks for providing the info. After adding the mentioned line bash_profile in the script, started executing properly from the crontab.

  5. #5
    Join Date
    Jan 2014
    Posts
    20
    Hi db2mor,

    Kindly let me know where I need to do the mentioned changes??

  6. #6
    Join Date
    Sep 2003
    Location
    United States
    Posts
    65
    Provided Answers: 1
    you can add the command in your script before running any db2 commands or in cron entry as follows

    * * * * * . ~db2inst1/sqllib/db2profile; <your script file name>
    >>
    >> Learn PHP/MySQL for free https://www.youtube.com/watch?v=mpQts3ezPVg
    >> Free Web Hosting with PHP, MySQL, Website Builder : http://www.000webhost.com/862861.html

  7. #7
    Join Date
    May 2012
    Location
    Canberra, Australia
    Posts
    176
    Provided Answers: 6
    this is useful
    http://linuxcommand.org/lc3_writing_shell_scripts.php
    check the error handling section
    Andy

    "All parts should go together without forcing. You must remember that the parts you are reassembling were disassembled by you. Therefore, if you can’t get them together again, there must be a reason. By all means, do not use hammer.” — IBM maintenance manual, 1975 "

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
  •