Shell script which runs sql script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script which runs sql script
# 1  
Old 11-14-2008
Question Shell script which runs sql script

Hi all,

I need a shell script which runs a sql script but I couldn't find how to finish it. This is the code that I have:

#! /usr/bin/ksh
export SHELL=/bin/ksh
export ORACLE_SID=database
export ORACLE_HOME=/opt/oracle/product/9.2.0.8
sqlplus user[/password][@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=database)(PORT=1637))(CONNECT_DATA=(SERVICE_NAME=database )))] [AS {SYSOPER}] <<EOF @/path/path/path/scriptname.sql
EXIT
EOF

When I run this code I am receiving the next message error:

Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
<logon> ::= <username>[/<password>][@<connect_string>] | / | /NOLOG
<start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
"-H" displays the SQL*Plus version banner and usage syntax
"-V" displays the SQL*Plus version banner
"-L" attempts log on just once
"-M <o>" uses HTML markup options <o>
"-R <n>" uses restricted mode <n>
"-S" uses silent mode

Any idea what I should change?

Thank you! Smilie
# 2  
Old 11-14-2008
I haven't called a script from within sqlplus, but your connection string looks off.

sqlplus username/password@dbhost:1637/dbsid <<EOF
desc somedbview;
quit
EOF

That command works ok from my end.
# 3  
Old 11-17-2008
thanks for your help, but it did not work.. another idea?
# 4  
Old 11-17-2008
well, finally my shell is done... my problem was that my user to access to database has a $ like abc$dfgh so, unix takes as a variable then I had to put quotation marks as:

sqlplus -S 'abc$dfgh/password@database' <<EOF @/path/path/path/scriptname.sql

and It worked!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

2. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

3. AIX

Script runs in shell but not cron

We run some menu driven software that has the ability to batch menu paths and generate reports quickly. Normally you run a batch like: $ BATCH BATCHNAME The batch program then prompts you for the date you want the report run for. I got some help from some folks on IRC to do the following: BATCH... (2 Replies)
Discussion started by: herot
2 Replies

4. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

5. Shell Programming and Scripting

Shell Script runs good manually but not through Cron tab

Hello Every one, I have a shell script which is running fine manually, but its giving me hard time when running tru cron job. :wall:. Am using #!/usr/bin/ksh >echo $SHELL /usr/bin/ksh Cron Job is as below, it execues but dosent do what i want it to do. 47 15 * * *... (1 Reply)
Discussion started by: naren.chowdhary
1 Replies

6. Shell Programming and Scripting

Shell script that runs a random shell script

Hi, im trying to make a shell script that basically runs a random shell script form a list of shell scripts i specify. Im not very good at writing shell scripts, and am new to linux. Thanks in advance :) (15 Replies)
Discussion started by: kylecn
15 Replies

7. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

8. Solaris

Sunsolaris shell script runs only as super user

Hi Friends, I am new to Sun solaris unix.I am facing problem while runing my kornshell script just as an ordinary user.The script works fine while i am working as a super user.the script just uses awk to check the first charcter of a file and then copies the file to another folder. Do i... (4 Replies)
Discussion started by: gjithin
4 Replies

9. Shell Programming and Scripting

Calling SQL LDR and SQL plus scripts in a shell script

Hi- I am trying to achieve the following in a script so I can schedule it on a cron job. I am fairly new to the unix environment... I have written a shell script that reads a flat file and loads the data into an Oracle table (Table1) via SQLLDR. This Works fine. Then, I run a nested insert... (5 Replies)
Discussion started by: rajagavini
5 Replies

10. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies
Login or Register to Ask a Question