Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'<<' unmatched Error 1

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello All,

I am trying to write a script to check if I can connect to the database, however I am getting unmatched error:
syntax error at line 14 : `<<' unmatched

Please help, here is my original code:
#!/usr/bin/ksh

###########################################################
#instance.ksh ##
###########################################################
DBALIST="xxx@xxx.com, yyyyy@yyy.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo "Oracle Database(s) Status `hostname` :\n"

db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
sqlplus -L "/as sysdba" <<!
@test.sql
exit
!

if [ `cat test.txt|wc -l` -gt 0 ] then
echo echo "Oracle Instance - $i: Up"
else
echo "Oracle Instance - $i is Down"| mailx -s "Instance is down"$DBALIST
fi
done
 
I can confirm that - there must be no white space of any sort before the !

I want to be good, is that not enough?
 
Not only can there be no white space before the ! but make sure there is none after it. Even 1 space after the ! will make the HERE document fail.
 
Hi

Or add a dash ( - ) and make sure you use tabs for indenting :
Code:
        sqlplus -L "/as sysdba" <<[red]-[/red]!
        @test.sql
        exit
        !
Not sure if all [tt]ksh[/tt] versions/implementations allows this.

Feherke.
 
tahnks for your suggestions everyone. However, I am still getting the same error after I used this method to get rid of the white spaces.

grep -v ^$ file.in > file.out

Please help
 
Here is my modofied code. Note, I just used the grep -v ^$ file.in > file.out
to remove the white space as sugested in the previouse post. here is my code:
#!/usr/bin/ksh
###################################################################
#instance.ksh ##
###################################################################
#DBALIST="7809173870@paging.rogers.com;tayo.ogundehinde@eds.com";export DBALIST
DBALIST="tayo.ogundehinde@eds.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo "Oracle Database(s) Status `hostname` :\n"
db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
sqlplus -L "/as sysdba" <<!
@test.sql
exit
!
if [ `cat test.txt|wc -l` -gt 0 ] then
echo echo "Oracle Instance - $i: Up"
else
echoecho "Oracle Instance - $i is Down"| mailx -s "Instance is down"$DBALIST
fi
done
 
Hi

Ok. Next time please post the code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] tags.

So where is the modification suggested by any of us ? It should look like either :
Code:
#!/usr/bin/ksh

###########################################################
#instance.ksh ##
###########################################################
DBALIST="xxx@xxx.com, yyyyy@yyy.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo  "Oracle Database(s) Status `hostname` :\n"

db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
        sqlplus -L "/as sysdba" <<!
        @test.sql
        exit
[COLOR=white red]![/color]

        if [ `cat test.txt|wc -l` -gt 0 ] then
                echo echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"|       mailx -s "Instance is down"$DBALIST
        fi
done
Code:
#!/usr/bin/ksh

###########################################################
#instance.ksh ##
###########################################################
DBALIST="xxx@xxx.com, yyyyy@yyy.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo  "Oracle Database(s) Status `hostname` :\n"

db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
        sqlplus -L "/as sysdba" <<[COLOR=white red]-[/color]!
[COLOR=white red]        [/color]@test.sql
[COLOR=white red]        [/color]exit
[COLOR=white red]        [/color]!

        if [ `cat test.txt|wc -l` -gt 0 ] then
                echo echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"|       mailx -s "Instance is down"$DBALIST
        fi
done

Feherke.
 
I used the code below and it is giving me :
test_new.sh[11]: syntax error at line 19 : `else' unexpected

Here is the code I used
Code:
#!/usr/bin/ksh
###################################################################
#instance.ksh ##
###################################################################
#DBALIST="7809173870@paging.rogers.com;tayo.ogundehinde@eds.com";export DBALIST
DBALIST="tayo.ogundehinde@eds.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo  "Oracle Database(s) Status `hostname` :\n"
db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
        sqlplus -L "/as sysdba" <<!
        @test.sql
        exit
!
        if [ `cat test.txt|wc -l` -gt 0 ] then
                echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"| mailx -s "Instance is down"$DBALIST
        fi
done
 
Hi

Code:
        if [ `cat test.txt|wc -l` -gt 0 ][COLOR=white red];[/color] then
                echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"| mailx -s "Instance is down"$DBALIST
        fi

Feherke.
 
There is got to be a simpler way of doing this. Please help. I have to admit I am not vast on scripting.

Here is my goal: I want to check to see if the database is open. I have four instances on the server. I delibrately shut down one. The idea is to
1)log into database, after getting the names of the instanace from ORATAB.
2)spool a file by getting the date from dual
3)cat the file and grep for SYSDATE, If it is there, then database is up, if not send email saying database is down.

BUT IT IS SAYING ALL THE 4 INSTANCES ARE UP....

here is my code once again.
Code:
#!/usr/bin/ksh
###################################################################
#instance.ksh ##
###################################################################
DBALIST="XXX@YYY.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo  "Oracle Database(s) Status `hostname` :\n"
db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
        sqlplus -L "/as sysdba" <<!
        @test.sql
        exit
!
        pslist="`cat text.txt`"
        echo  "$pslist" | grep  "SYSDATE"  > /dev/null 2>$1
        if (( $? )); then
                echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"| mailx -s InstanceDown $DBALIST
        fi
done
 
Thanks for all your help everyone.

I have been able to figure out my mistake and corrected them.

Again thanks.
 
Note, I just used the grep -v ^$ file.in > file.out to remove the white space as sugested in the previouse post.

That only removes blank lines. That is not the whitespace that we're talking about here. Whitespace is any one of a number of characters that you can't see, like a blank or space (" "), or a tab character. The way you were starting the "here file" means that your ending character "!" had to have no leading spaces or tabs in front of it on just that line. It didn't mean you couldn't have blank lines. In fact you could have as many blank lines as you want.

feherke's suggestion of adding the dash ("<<-!") is the best because then it doesn't matter if you have leading spaces or tabs. You don't have to worry about someone later on maintaining the code indenting it to make it look better, and thus breaking the code accidentally.

I also often recommend against using something like a punctuation mark to delimit "here files". It's not always so obvious what it's for and again, can be messed up by someone later maintaining the code. I usually use something like "SQLCMDS" to clearly delimit what the "here file" is for. That would make it look like...
Code:
#!/usr/bin/ksh

###########################################################
#instance.ksh ##
###########################################################
DBALIST="xxx@xxx.com, yyyyy@yyy.com";export DBALIST
ORATAB=/var/opt/oracle/oratab
echo "`date` "
echo  "Oracle Database(s) Status `hostname` :\n"

db=`egrep -i ":Y|:N" $ORATAB | cut -d":" -f1 | grep -v "\#" | grep -v "\*"`
for i in $db ; do
[b]        sqlplus -L "/as sysdba" <<-SQLCMDS
            @test.sql
            exit
        SQLCMDS
[/b]
        if [ `cat test.txt|wc -l` -gt 0 ] then
                echo echo "Oracle Instance - $i:       Up"
        else
                echo "Oracle Instance - $i is Down"|       mailx -s "Instance is down"$DBALIST
        fi
done

If you're delimiting FTP commands, use "FTPCMDS". If it's just shell script commands, just "CMDS" works. You can use anything you want, but I find it makes the code more maintainable if you use something that describes what the "here file" does.


 
Hi

SamBones said:
feherke's suggestion of adding the dash ("<<-!") is the best because then it doesn't matter if you have leading spaces or tabs.
Actually spaces are not removed, only tabs.
man ksh said:
If - is appended to <<, then all leading tabs are stripped from word and from the document.
man pdksh & man mksh said:
<<-marker Same as <<, except leading tabs are stripped from lines in the here document.
man bash said:
If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter.
Personally I never use it. If you later edit the script with an editor which expands tabs to sequence of spaces, your code will be messed. ( Additionally, as a personal opinion, indenting with tabs is ugly. )

Feherke.
 
feherke said:
...indenting with tabs is ugly.

Why not indent with tabs? That's what they're for. Any editor that converts them to spaces is evil, and should not be used, IMO. I always use tabs... and if my level of nesting is getting too deep (usually means I'm being lazy and not making my code modular enough), I just ':set ts=4 sw=4' in vi. Also, if you don't use tabs, it makes the << and >> commands in vi useless, unless you somehow make these use spaces too? Also, why use 8 bytes when 1 will do?

A personal opinion too, I'm just curious. ::)

Annihilannic.
 
Well, one reason I especially don't like tab-indentation is when I copy/paste in vi sessions in PuTTY for instance, the tabs are always copy/pasted as up to 8 spaces...

[tt]
So
I
vote
for
spaces
and
besides,
I
never
use
>> or <<
in
vi
period.
[/tt]

And that is my personal (in)dented? opinion :).


HTH,

p5wizard
 
Granted, but nothing that :%s/ /^I/g won't fix. ;-) I couldn't live without >} and <} for in/undent paragraph when coding/scripting. What would you do instead, :set nu and :53,168s/^/ /?

Annihilannic.
 
I (ahum) don't have to in/undent paragraphs all that much...
But I will certainly keep your tips in the back of my memory.

If it weren't off topic to this discussion I'd even star you for it.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top