cancel
Showing results for 
Search instead for 
Did you mean: 

Embed svrmgl in shell script !

Chris Fung
Frequent Advisor

Embed svrmgl in shell script !

Hi all,

I have problem to run svrmgl in batch mode in shutting and starting up the database when I put the below quote code within if-then-else clause. However, I am able to execute it successfully without the if-then-else clause. Anyone can help ??

Quote 1: This example works fine !!

su oracle "-c $ORACLE_BIN/svrmgrl" <connect internal;
shutdown immediate;
exit;
EOF

Unquote 1

Quote 2: This example doesn't work

if [[ `ps -ef |grep -v grep |grep pmon |wc -l` -gt 1 ]]
then

su oracle "-c $ORACLE_BIN/svrmgrl" <connect internal;
shutdown immediate;
exit;
EOF

fi

Unquote 2

The strange thing is the Shell return me syntax error for the redirect symbol "<".

Many thanks,

Chris
7 REPLIES
steven Burgess_2
Honored Contributor

Re: Embed svrmgl in shell script !

Hi

The redirect symbol is because the shell is basically telling you that your command is incomplete.

Try single [ around your if statement

also

Your su comment

try

su oracle -c 'ORACLE_BIN/svrmgrl' <
Hope this helps

Steve

take your time and think things through
steven Burgess_2
Honored Contributor

Re: Embed svrmgl in shell script !

Also

Have been speaking with our dba who advised that your shutdown method is a little dirty

If you have client server applications that connect you should really stop the listener first so that new users can't connect, then kill user processes then perform a shutdown

HTH

Steve
take your time and think things through
Wodisch_1
Honored Contributor

Re: Embed svrmgl in shell script !

Hi Chris,

your quoting is the problem:

su oracle -c "$ORACLE_BIN/svrmgrl" <
is what it should look like...

Just my $0.02,
Wodisch
Bill Hassell
Honored Contributor

Re: Embed svrmgl in shell script !

And just a note about this construct:

if [[ `ps -ef |grep -v grep |grep pmon |wc -l` -gt 1 ]]


Whenever you see ps and grep together, you've got big problems. The above string comparison will find totally unrelated processes!!! That's necause grep matches anything on the line and that is definitely not what you want. ps has 100x better search capability built in. The following will do what you want to accomplish:

if [ $(UNIX95= ps -C pmon | wc -l) > 1 ]
then

UNIX95 is a special variable that should be used in the above method (temp assignment, don't export it) and turns on many new features in ps including an exact process name match. The above -C pmon will never find processes such as pmon1 or upmon or processes with pmon on the command line or users with pmon in their name.


Bill Hassell, sysadmin
Scott Benitez
Occasional Advisor

Re: Embed svrmgl in shell script !

Also, just as a note, with 9i, svrmgrl is no longer supported. Everything is done with sqlplus.

The following commands to connect are good from 8.0 thru 9i.

oracle$ sqlplus /nolog
SQL> connect / as sysdba

You will need an orapwd file to allow the sysdba connection.

If you only have 1 db, or plan on using this to shutdown all the databases prior to system shutdown/reboot, oracle still supports the $ORACLE_HOME/bin/dbshut commands that will cycle through the oratab and shutdown all the databases indicated with a "Y". (There were some problems with dbshut/dbstart in 8i, but the fixes are readily available on Metalink for this.

Scott
Die Laughing
Tom Geudens
Honored Contributor

Re: Embed svrmgl in shell script !

Hi Chris,
Since I didn't see any answer rated above 5, I presume you still haven't solved your problem ? All the above information is excellent, but one thing didn't get mentioned. The EOF should / must / has to start in the first position. Your script doesn't show indentation, so probably this is a moot point, but often "what you paste isn't what you get", so I thought I'd mention it. I've often made the mistake myself of putting blanks before the EOF (making the if statement clearer) and then wondering what happened ... :-)

Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Chris Fung
Frequent Advisor

Re: Embed svrmgl in shell script !

Dear all,

Thanks for all your suggestions. I've used a work around solution to put the svrmgl block to another script and embed a system call to the svrgmrl script within the if - then - else routine and it works.

Cheers,

Chris,