Operating System - HP-UX
1826451 Members
3910 Online
109692 Solutions
New Discussion

Script help with " << EOF " errors...

 
SOLVED
Go to solution
Sally  Devine
Frequent Advisor

Script help with " << EOF " errors...

Hello,

I have written a script to bring up/down oracle databases. I am getting the following error : syntax error "<<" unmatched

Here is the script

#!/bin/ksh

# THIS SCRIPT WILL BE USED TO STARTUP AND SHUTDOWN THE DATABASES
# NOTE: You must supply a start/stop on command line (ie db start)
# - Nitro Microsystems -


ACTION=$1
DATABASE=`/usr/bin/grep oracle /etc/oratab|grep -v "*"|awk '{FS=":"}{print $1}'`
ORA_PATH=`/usr/bin/grep oracle /etc/oratab|grep -v "*"|awk '{FS=":"}{print $2}'|
/usr/bin/head -1`
SVR=/usr/oracle/product/8.0.5/bin/svrmgrl

# ENSURE THAT AN ACTION HAS BEEN GIVEN - IE START OR STOP
if [ -z "${ACTION}" ]
then
echo
echo "You must supply a start or stop command"
echo
echo "USAGE : db.ksh start or db.ksh stop"
echo
exit 1

case $ACTION in
'stop')
for DB in $DATABASE
do
export ORACLE_SID=$DATABASE
export PATH=.:$ORA_PATH/bin:$PATH
$SVR << EOF
connect internal
shutdown immediate
EOF
done
;;

'start')
for DB in $DATABASE
do
export ORACLE_SID=$DATABASE
export PATH=.:$ORA_PATH/bin:$PATH
$SVR << EOF
connect internal
startup
startup
done
;;

*)
echo
echo YOUR START/STOP COMMAND WAS INCORRECT...ensure that it is
echo in lowercase IE: db.ksh start or db.ksh stop
echo
;;
esac

Not sure why this will not work. Thanks for the help,
Sally
12 REPLIES 12
Christopher Caldwell
Honored Contributor

Re: Script help with " << EOF " errors...

There's a trailing EOF in your stop command, but there isn't one in your start command.

blah << EOF
blah
blah
blah
EOF <------ you left this one out on start
Michael Tully
Honored Contributor

Re: Script help with " << EOF " errors...

Hi,

Try adding "EOF" before the 'done'in your start section. The stop section has one but not the start.

HTH
-Michael
Anyone for a Mutiny ?
Sally  Devine
Frequent Advisor

Re: Script help with " << EOF " errors...

Sorry, just a bad cut and paste job...it is actually there in the original and is not working.

I just wrote a little test script where I ran:

svrmgrl >> EOF
show all
EOF

and everything was fine. It looks like it doesn't like being in a FOR loop for some reason.

Any more ideas?

Thanks for the help.
Bill Hassell
Honored Contributor
Solution

Re: Script help with " << EOF " errors...

The forums text handler always left justifies text and removes redundant spaces. No matter how you format your script, the here-document terminator (EOF in this case) must start in column 1 in order to be recognized.


Bill Hassell, sysadmin
Michael Tully
Honored Contributor

Re: Script help with " << EOF " errors...

Hi Sally,

I'm not an oracle person, but in the attached
link should be something of use.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2c268ffa98a2d5118ff10090279cd0f9,00.html

HTH
-Michael
Anyone for a Mutiny ?
harry d brown jr
Honored Contributor

Re: Script help with " << EOF " errors...

Sally,

Take a look at this, and possibly other perl solutions:
http://www.tux.org/orac-dba/resources.html

live free or die
harry
Live Free or Die
Steven Sim Kok Leong
Honored Contributor

Re: Script help with " << EOF " errors...

Hi,

In your response, you quoted a test you performed:

svrmgrl >> EOF
show all
EOF

Another typo? It should be << not >>.

If you are using << correctly and not >>, I agree with Patrick that it is most likely that your EOF is not properly left-aligned in the first column.

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Sally  Devine
Frequent Advisor

Re: Script help with " << EOF " errors...

Thank you all very much. As it turns out

connect internal
startup
EOF

all have to be left-aligned. I never would have figured that out.

Thanks again,
Sally - sorry for all the typos!
Magdi KAMAL
Respected Contributor

Re: Script help with " << EOF " errors...

Hi Sally,

$SVR<
means that the input of Oracle Server Manager will be redirected to be from then following text and not from the keyboard, as it is a batch script.

and the end of this input will be notified by the next appearance of the label EOF.

You need :

To close your input text for $SVR<
Greetings.

Magdi
Wodisch
Honored Contributor

Re: Script help with " << EOF " errors...

Hello Sally,

the "EOF" *MUST* be left aligned, but if you want the redirected text lines to be indented, you have to prefix the "EOF" mark with a dash:

cat <<-EOF
________is
________shown
________left-aligned
EOF

Since the forums server does not like space, please replace all underscores '-' with spaces ' ' in the above example...

Substitutions still happens within the redirected lines,
but if you not want that you have to single-quote the mark
(i.e. "cat <<'EOF'" or even "cat <-'EOF'")...

HTH,
Wodisch
Joseph C. Denman
Honored Contributor

Re: Script help with " << EOF " errors...

Sally,

FYI

Oracle provides standard scripts for this purpose. $ORACLE_HOME/bin/dbshut and $ORACLE_HOME/bin/dbstart

In your start section of the script run dbstart, and in the stop section, run dbshut. The way I look at is, WHY REINVENT THE WHEEL???

Good Luck,

...jcd...
If I had only read the instructions first??
Joseph A Benaiah_1
Regular Advisor

Re: Script help with " << EOF " errors...

Sally,

Try this example:

echo 'connect internal\nselect * from v$database;\nexit\n' | svrmgrl > /tmp/svrmgrl.out

I have used this in a shell script to determine if an Oracle instance is in archive log mode.

Regards,

Joseph.