Skip to Main Content
  • Questions
  • Shell function returning content of existing directory along with error code

Breadcrumb

May 4th

Question and Answer

Connor McDonald

Thanks for the question, VIDYASAGAR.

Asked: March 09, 2018 - 3:42 pm UTC

Last updated: March 13, 2018 - 11:39 am UTC

Version: 12.1.0.2

Viewed 1000+ times

You Asked

Hi,

We are using following code to find out ORA- errors. But not sure why it is returning directory contents on function error.


db_scn()
{
OUTPUT=$(sqlplus -s /as sysdba << EOT
whenever SQLERROR EXIT 11
select ccurrent_scn from v$database; ##intentionally kept ccurrent to return error code
select sysdate from dual;
EOT)
echo $OUTPUT
}

db_scn


and Connor said...

You were missing a space between the "/" and sysdba.

But I prefer this method:

#!/usr/bin/ksh
db_scn()
{
print '
whenever SQLERROR EXIT 11
select ccurrent_scn from v$database; 
select sysdate from dual;
exit'  | sqlplus / as sysdba 2>&1 | egrep '(ORA-|SP2)'
}

db_scn


which lets you not have to worry about escaping $ signs, and easy to grep for particular output etc.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Cut'n'paste error?

AndyP, March 13, 2018 - 8:53 am UTC

Hi Connor - looks like you reposted the original code in your reply. Could you revisit this one do you think, as it seems from your comment that it would be a useful approach?
Connor McDonald
March 13, 2018 - 11:39 am UTC

Whoops !!! Corrected. Thanks for letting us know.