The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in passing a variable to sqlplus from a shell script kripssmart Shell Programming and Scripting 3 07-08-2008 08:01 PM
To pass the .sql file as a paramter to sqlplus through shell programming Hemamalini Shell Programming and Scripting 9 06-17-2008 07:34 AM
error in running shell script in cron sari Shell Programming and Scripting 3 04-16-2008 05:09 AM
running shell script from sqlplus dkr123 Shell Programming and Scripting 9 07-20-2006 11:52 PM
Running SQLPLUS from Shellscripting ... chittari Shell Programming and Scripting 2 06-12-2006 05:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-06-2009
mmunir mmunir is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
error running sqlplus from shell file

I am running a shell file following script on bash shell in solaris 10

(
echo abc@orcl
echo abc
echo "set feedback off"
echo "truncate table SIndexDataTypeHst1_changes;"
) | sqlplus -s

but getting the following error

ERROR:
ORA-01005: null password given; logon denied



ERROR:
ORA-12162: TNS:net service name is incorrectly specified


SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> ::= <username>[/<password>][@<connect_identifier>] | /
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus


user/password and service all are correct.

Can any body tell me where i am going wrong?
  #2 (permalink)  
Old 02-06-2009
sunpraveen's Avatar
sunpraveen sunpraveen is offline
Registered User
  
 

Join Date: Jan 2009
Location: Pruthvi
Posts: 85
I always call sqlplus command in the following way and it has always worked.
Code:
login=username/password@tns_entry
sqlplus -s "$login" << EOF
@your_script.sql
OR
set head off
set verify off
select sysdate from dual;
EOF
Also, by seeing your error it is obvious that you are trying to connect as sys user without having the correct privileges to do so.

As far as possible, avoid connecting as sys user in scripts. Try using system user instead.

HTH,

Regards,

Praveen
  #3 (permalink)  
Old 02-06-2009
mmunir mmunir is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
Thanks for the reply.

but i want to find the problem in the script mentioned in my question.

Moreover, i am not trying to connect as sysdba.
  #4 (permalink)  
Old 02-06-2009
sunpraveen's Avatar
sunpraveen sunpraveen is offline
Registered User
  
 

Join Date: Jan 2009
Location: Pruthvi
Posts: 85
Munir,

The problem in your script is twofold.

1. Through a script, sqlplus CANNOT accept the password, if supplied independently of the username. It has to supplied with the username using the forward slash ("/").

eg: The below code does NOT work:

Code:
$ (
> echo abc@orcl
> echo abc
> echo "set head off"
> echo "select sysdate from dual;"
> ) | sqlplus -s
while the below code WORKS:

Code:
$ (
> echo abc/abc@orcl
> echo "set head off"
> echo "select sysdate from dual;"
> ) | sqlplus -s
2. Since sqlplus is unable to parse the input (because of point 1 above), it is throwing both TNS error as well as the login error.

The below code should work and is as per your requirements (although I prefer the method that I mentioned in my earlier reply ):

Code:
$ (
> echo "abc/abc@sid"
> echo "set feed off"
> echo "set verify off"
> echo "set head off"
> echo "select sysdate from dual;"
> ) | sqlplus -s

06-FEB-09
$
HTH,

Regards,

Praveen
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0