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.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How can i Connect to a database via UNIX Shell Script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-07, 07:27
bharaniks bharaniks is offline
Registered User
 
Join Date: Nov 2007
Posts: 1
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.
Reply With Quote
  #2 (permalink)  
Old 11-06-07, 10:54
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #3 (permalink)  
Old 12-10-07, 00:47
drogomoss drogomoss is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 12-18-07, 06:38
J.Poornima J.Poornima is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On