- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- if then else script wont work with oracle command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 10:39 AM
04-18-2005 10:39 AM
I am modifying an old bourne shell script in which there is a part that does:
sqlplus xxx/yyy << EOF
select stuff from mytable
/
EOF
This works fine, until I put it into a conditional statement:
if [ $1 = "PROD" ]
then
sqlplus xxx/yyy << EOF
select stuff from mytable
/
EOF
else
sqlplus xxx/yyy << EOF
select otherstuff from mytable
/
EOF
fi
this fails with 'else' is not expected
why does this not work?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 10:55 AM
04-18-2005 10:55 AM
Re: if then else script wont work with oracle command
differently. Run the script with debug mode
(i.e ksh -x script) and see if it helps you.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 11:55 AM
04-18-2005 11:55 AM
Re: if then else script wont work with oracle command
I made this test:
A=y
if [[ $A = "x" ]]
then
sqlplus system/manager <
/
exit;
EOF
else
sqlplus system/manager <
/
exit;
EOF
fi
And it worked well.
I think you have some "strange" character, like backspace, inside your command.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 07:32 PM
04-18-2005 07:32 PM
Re: if then else script wont work with oracle command
try running your shell :
sh -x shell.sh PROD
This should help you debug what is happening.
Perhaps you should check your EOF labels and rename the second set of EOFs to something else, add exits to the sqlplus statements and add -s after sqlplus to suppress banner.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 07:55 PM
04-18-2005 07:55 PM
Re: if then else script wont work with oracle command
If you like to use indentation, use a minus sign i.e.:
...
to ignore leading tabs
For security reasons, try sqlplus << EOF
system/manager
EOF
or sqlplus /nolog <
EOF
in stead of sqlplus system/manager << OEF
...
EOF, because with an ps command the login/password will be shown
You might try another construction:
case $1 in
PROD)
stmt="select 'blah' from dual; "
;;
TEST
stmt="select 'halb' from dual"
;;
esac
sqlplus << EOF
connect system/manager
$stmt;
EOF
That's faster, because case is a shell built-in
Hope this helps,
Renarios
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2005 10:37 PM
04-18-2005 10:37 PM
Re: if then else script wont work with oracle command
i would check if no "strange characters" is polluing the script or a coma somewhere. that's often the problem !
don't you have a line error seeing by the shell ( "error line xx") ??
otherwise the debug will work fine for a command error or an in/out-put error
HTH
E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 01:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 01:54 AM
04-19-2005 01:54 AM
Re: if then else script wont work with oracle command
if [ $1 = "PROD" ]
then
stuff="whatever"
else
stuff="whatever else"
fi
sqlplus xxx/yyy << EOF
select ${stuff} from mytable
/
EOF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 02:13 AM
04-19-2005 02:13 AM
Re: if then else script wont work with oracle command
#Create a temporary file
TDIR=${TMPDIR:-/var/tmp}
S1=${TDIR}/X${$}_1.sql
trap '{eval rm -f ${S1}' 0 1 2 15
# Trap forces removal of temp file upon exit
# or interrupt
#Now simply use echo satements to build up #the sql file
rm -f ${S1} # null the file
if [ "${1}" = "PROD" ]
then
echo "select stuff from mytable;" >> ${S1}
echo "exit;" >> ${S1}
fi
# this could be extended as needed perhaps
# using a case statement rather than if's
sqlplus xxx/yyy @${S1}
# You don't need to remove the temp file
# The trap takes care of that for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2005 02:55 AM
04-19-2005 02:55 AM