Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 08: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, 11:54
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Posts: 1,646
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
Data Warehousing on System z
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 12-10-07, 01:47
drogomoss drogomoss is offline
Registered User
 
Join Date: Mar 2007
Posts: 27
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, 07: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

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