Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2007
    Posts
    1

    Unanswered: How can i Connect to a database via UNIX Shell Script

    Hi,

    Can any one please provide me a sample Shell Script which
    Connects to a database and proceed with basic commands.

    Thankyou.

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Assuming you use DB2 as database system, it is really straight-forward:
    Code:
    #!/bin/sh
    
    db2 "connect to dbname"
    ls
    db2 "select count(*) from syscat.tables"
    mkdir abc
    db2 "connect reset"
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Mar 2007
    Posts
    30
    Hello there,

    Script below done in AIX/RS6000/DB2

    --------------------
    #!/bin/ksh

    #---- Set Environment
    mdmdb="mydatabase"
    mdmdbuser="myusername"
    mdmdbpwd="mypassword"

    #---- Connect to the Database
    db2 connect to $mdmdb user $mdmdbuser using $mdmdbpwd

    #
    # Whatever you want to do goes here...
    #

    #---- Terminate DB2
    db2 terminate

    Hope this helps.

    Merry Christmas.

  4. #4
    Join Date
    Mar 2007
    Posts
    25
    Assuming that you want to connect to Sybase

    Method 1: Using Here Documents

    isql -U<user name> -P<password> -S<server name> -o output.txt ............ << EOF
    Whatever you want to do in the sybase
    EOF

    Method 2: using the input file parameter of isql

    isql -U<username> -P<password> -S<server name> -i<input file> -o <output file>
    where the input file will contain all what you want to do when the connection is established.

    Regards,
    Poornima

Posting Permissions

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