How Connect to a Database in Shell Programming?Please tell me Step by Step?

Showing Answers 1 - 16 of 16 Answers

Suppose you are using db2 and ksh

----------------------------

#!/usr/bin/ksh

connect to <Serve Name>:<Port NO>@<Instance Name> user <USERID> using <Passwd>

-----------------------------------

If u have profile and catalog then

----------------------------------

#!/usr/bin/ksh

db2 connect to <SID>

-----------------------------------

To run a sample proc .. use the below

db2 "<Proc Name>"

Thanks,

an

  Was this answer useful?  Yes

To Connect to Oracle Database and Collect the data in to text file from the table.echo "Enter User Name "read nameecho "Enter passwd "stty -echoread passstty echoecho "Enter Detp no"read dnosqlplus -S $name@oracle/$pass<

  Was this answer useful?  Yes

Ramakrishna.P

  • Aug 30th, 2006
 

Hi all,

By using shell script,

#!user/bin/bash

sqlplus ' / as sysdba ' >>EOF

startup

shutdown immediate >>EOF

  Was this answer useful?  Yes

cmanne

  • Mar 25th, 2007
 

Hi,
In oreder to connect to a database using a shell script it is always necessary to set the environment first and then connect to the database and execute whatever the statements u need to and come out of the script gracefully.

ex:
#!/bin/sh
export ORACLE_SID=$1
export ORACLE_HOME=more /etc/oratab|grep -v '#'|grep -i $1|cut -d":" -f2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export PATH=$ORACLE_HOME/bin:$HOME/bin:$PATH

sqlplus -s sys/<passwd> as sysdba <EOF
select name from v$database;
archive log list;
exit
EOF

The above script echoes the name of the database you are connected along with the archive log mode information.

  Was this answer useful?  Yes

jrgalaura

  • Oct 27th, 2008
 

To connect to sybase, write this in the command line:

isql -Sservername -Uusername -Ppassword
1>use database
2>go

when you're done, just type quit.

Although i don't recommend using the -P option as other people might see your password.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions