Not able to execute sql command in shell script [message #355060] |
Wed, 22 October 2008 07:27 |
ranvijaidba
Messages: 71 Registered: May 2008 Location: Bangalore
|
Member |
|
|
I made one script to shutdown all oracle database that is running on server.I am checking Oracle process for this.But when i am running this script it is not recognizing sql command.Please tell me where i am wrong .I am not comfortable in shell scripting
This is the script:
#!/bin/sh
############################# ARMANI DATABASE SHUTDOWN #########################
BASE_DIR=/home/oracle
export BASE_DIR
cd $BASE_DIR
for db in `ps -ef|grep pmon|grep -v grep|awk '{print $8}'|sed -e 's/ora_pmon_//g'|grep -v sed`
do
echo "Loading $db database profile..........."
. $BASE_DIR/$db
echo "Shutting $db database..."
sqlplus/nolog < EOF >$BASE_DIR/dblog/db.log
connect sys/ski4now as sysdba
SET LINESIZE 100
SET PAGESIZE 50
SET heading off feedback off verify off
select sysdate from dual;
shutdown immediate;
exit
echo "$db database closes normall"
EOF
done
exit
##########Checking for any running database####################
if [ `ps -ef|grep pmon |wc -l` -ge 1 ]
then
echo " Database is running Please Check error log file for Shutdown error"
else
echo "***All Database is closed*******"
exit 1
fi
exit
Note: Only for testing i am passing "select sysdate from dual"
Error is:
[oracle@ssipl-srvr-027 ~]$ ./shutdbs.sh
./shutdbs.sh: line 16: syntax error near unexpected token `from'
./shutdbs.sh: line 16: ` select sysdate from dual;'
[EDITED by LF: added [code] tags]
[Updated on: Mon, 03 November 2008 04:17] by Moderator Report message to a moderator
|
|
|
|
Re: Not able to execute sql command in shell script [message #355242 is a reply to message #355101] |
Thu, 23 October 2008 03:54 |
ranvijaidba
Messages: 71 Registered: May 2008 Location: Bangalore
|
Member |
|
|
I correct it but getting error...
I think some problem in for loop because it is also not showing message that i want to print.
I simplified script without sending output to any file.
#!/bin/sh
BASE_DIR=/home/oracle
export BASE_DIR
cd $BASE_DIR
for db in `(ps -ef|grep pmon|grep -v grep|awk '{print $8}'|sed -e 's/ora_pmon_//g'|grep -v sed)`
do
echo "Loading $db database profile..........."
. $BASE_DIR/$db
echo "Shutting $db database..."
sqlplus /nolog <<EOF
connect sys/ski4now as sysdba
SET LINESIZE 100
SET PAGESIZE 50
SET heading off feedback off verify off
select sysdate from dual;
exit
EOF
echo "$db database closes normall"
done
##########Checking for any running database####################
if [ `ps -ef|grep pmon |wc -l` -ge 1 ]
then
echo " Database is running Please Check error log file for Shutdown error"
else
echo "***All Database is closed*******"
fi
exit
but getting error:
[oracle@ssipl-srvr-027 ~]$ ./shutdbs.sh
./shutdbs.sh: line 29: syntax error: unexpected end of file
[oracle@ssipl-srvr-027 ~]$
[EDITED by LF: added [code] tags]
[Updated on: Mon, 03 November 2008 04:17] by Moderator Report message to a moderator
|
|
|
|
Re: Not able to execute sql command in shell script [message #355289 is a reply to message #355274] |
Thu, 23 October 2008 06:19 |
ranvijaidba
Messages: 71 Registered: May 2008 Location: Bangalore
|
Member |
|
|
Hi ebrian,
Thanks i am only checking with select command.if it recognize select command that there is no problem in executing shutdown command.
This is the code after replacing select command with shutdown immediate.Getting same error in both case.
#!/bin/sh
############################# ARMANI DATABASE SHUTDOWN #########################
BASE_DIR=/home/oracle
export BASE_DIR
cd $BASE_DIR
for db in `(ps -ef|grep pmon|grep -v grep|awk '{print $8}'|sed -e 's/ora_pmon_//g'|grep -v sed)`
do
echo "Loading $db database profile..........."
. $BASE_DIR/$db
echo "Shutting $db database..."
sqlplus /nolog <<EOF
connect sys/ski4now as sysdba
SET LINESIZE 100
SET PAGESIZE 50
SET heading off feedback off verify off
shutdown immediate;
exit
EOF
echo "$db database closes normal"
done
##########Checking for any running database####################
if [ `ps -ef|grep pmon |wc -l` -ge 1 ]
then
echo " Database is running Please Check error log file for Shutdown error"
else
echo "***All Database is closed*******"
fi
exit
Error:
[oracle@ssipl-srvr-027 ~]$ ./shutdbs.sh
./shutdbs.sh: line 29: syntax error: unexpected end of file
[oracle@ssipl-srvr-027 ~]$
Thanks for prompt reply.
[EDITED by LF: added [code] tags]
[Updated on: Mon, 03 November 2008 04:16] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|