LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2009, 06:13 AM   #1
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Rep: Reputation: 15
error in if statement


Hi,

This is my script to catch any oracle errors.

In this, the $sqlerr returns
ORA-01017: invalid username/password; logon denied
when i specify wrong username/password

the if condition is failing. how can i resolve the issue.

The if statement gives error [: too many arguments
sqloutput=`sqlplus -s -L $dasDBConnectString @$SqlFiles/testSQLConnection.sql`
sqlerr=`echo "$sqloutput" | grep "ORA-"`
echo $sqlerr
if [ -n $sqlerr ] #sql connection error
then
Status=10
else
Status=$?
fi
 
Old 03-18-2009, 06:43 AM   #2
tizzef
Member
 
Registered: Jan 2005
Location: Nice, France
Distribution: Ubuntu,RHES, Mandriva, RHAS, AIX 4.3.3, 5.2 & 5.3, Debian,Solaris8/10
Posts: 119

Rep: Reputation: 20
Hi

try this :

Quote:
if [[ -n $sqlerr ]] #sql connection error
then
Status=10
else
Status
Cheers
 
Old 03-18-2009, 09:20 AM   #3
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
There are spaces in $sqlerr so it needs to be enclosed in quotes. Try
if [ -n "$sqlerr" ]
 
Old 03-18-2009, 09:27 AM   #4
kpraveen455
Member
 
Registered: Feb 2009
Location: Hyderabad
Distribution: fedora
Posts: 33

Rep: Reputation: 17
Any time if you get the following error means the
"if" statement has string (with spaces)

"The if statement gives error [: too many arguments"

Example:

a="hi hw are you"
if [ -n $a ] ;then <--- will give error
echo blah
else
echo blah
fi

Put in double quotes

a="hi hw are you"
if [ -n "$a" ] ;then <--- works fine
echo blah
else
echo blah
fi

Last edited by kpraveen455; 03-18-2009 at 09:29 AM.
 
  


Reply

Tags
if



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl dbi module error "error at dbi:" dbi-> connect statement mysql haxpak Linux - Newbie 1 02-25-2009 08:22 AM
Problem with if statement in a find -exec statement romsieze Programming 2 10-02-2008 12:38 AM
error: expected declaration or statement at end of input ? psernaalvarez Programming 3 02-16-2008 02:35 PM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
label at the end of compuound statement error isuck@linux Linux - Software 3 08-31-2007 02:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration