1753774 Members
7137 Online
108799 Solutions
New Discussion юеВ

Re: EOF

 
SOLVED
Go to solution
Paul_481
Respected Contributor

EOF

Hi All,

export ORACLE_HOME=/opt/oracle/product/9.2
export ORACLE_SID=idmp005
export PATH=$PATH:/opt/oracle/product/9.2/bin:.
lsnrctl stop
/bin/cat <@/home/oracle/bin/stop.sql
exit
EOF

As you can see from the script above this will stop the listener and the oracle database.

Can anyone explain to me how "EOF" and "@" work in this script, also where can I put the "lsnrctl start" command if I want this script to start the listener and database.

Thanks,
Paul
5 REPLIES 5
Leif Halvarsson_2
Honored Contributor

Re: EOF

Hi

The EOF is the end of the sqlplus commands
and, @ is a part of the oracle connect string. Starting listener and database works exact as starting.


Hi
export ORACLE_HOME=/opt/oracle/product/9.2
export ORACLE_SID=idmp005
export PATH=$PATH:/opt/oracle/product/9.2/bin:.
lsnrctl stop
/bin/cat <@/home/oracle/bin/stop.sql
exit
EOF


lsnrctl start
/bin/cat <@/home/oracle/bin/start.sql
exit
EOF
Bejoy C Alias
Respected Contributor
Solution

Re: EOF

Here the line /bin/cat <
U can try it in a command line itself. Try '/bin/cat <' prompt to enter ur commands which will be redirected to the sql prompt , here enter some sql queries like 'select' etc. , now type exit which will exit from the sql prompt ( this will not be visible for u that u exited from the sql prompt ) , now type EOF , which will complete the command block of cat . Now u will get the out put of ur select commands.

U can use a script like below to startup ur database.

export ORACLE_HOME=/opt/oracle/product/9.2
export ORACLE_SID=idmp005
export PATH=$PATH:/opt/oracle/product/9.2/bin:.
/bin/cat <startup
exit
EOF
lsnrctl start
Be Always Joy ......
vasundhara
Frequent Advisor

Re: EOF

EOF is used in conventional way. You can use any pattern here. shell executes all the commands till it reads the same characters.

for example,

/bin/cat <@/home/oracle/bin/stop.sql
exit
SQLFROMSHELL
Stuart Browne
Honored Contributor

Re: EOF

Well the others have said how it works, but just a few more details.

The 'EOF' thing is called a "here document".

Most modern shells have the ability to use them to encompass multiple lines of 'text', and can be used for pretty much any purpose. Combined with a pipe, they are useful tools.

Even Perl can use here documents (see man perlop, search for '<
The thing to note is that the end-token is case specific (has to be identical to the opening-token), and can have no leading spaces or other characters.

Basically, the here document extends the STDIN for the command it is <<'d (input-redirected) into. So in reality, you could probably just <
One long-haired git at your service...
Tom Schroll
Frequent Advisor

Re: EOF


You can pipe directly into sqlplus. And I think you can also use "sqlplus <<" too, but I prefer the syntax below:

Here is what I have in our Oracle startup scripts.

Example 1: runs as root when the system boots:

($SU and $USER1 would be assigned according to your system; $SU is your path to su or sudo, $USER1 is the dba account)

cat << _EOF_ | ($SU - $USER1 -c "sqlplus /nolog")
connect oradb/oradb as sysdba;
startup;
exit;
_EOF_


Example 2: runs directly as the dba user:

cat << _EOF_ | sqlplus /nolog
connect oradb/oradb as sysdba;
startup;
exit;
_EOF_


If you really want to be fancy, you can put tabs in the code and then use <<- (note the addition of the dash (-). This little trick works for sh (posix), ksh and bash:

cat <<- EOF | sqlplus /nolog
[tab] connect oradb/oradb as sysdba;
[tab] startup;
[tab] exit;
[tab] EOF

(I spelled out [tab] here because the forum does not handle tabs in postings very well).

-- Tom


If it ain't broke, it needs optimized.