basic bash help

  • From: "Stephens, Chris" <Chris.Stephens@xxxxxxx>
  • To: "'oracle-l@xxxxxxxxxxxxx' (oracle-l@xxxxxxxxxxxxx)" <oracle-l@xxxxxxxxxxxxx>
  • Date: Fri, 27 May 2011 13:42:28 -0500

I'm writing a script to allow the sysadmin's to kill any active sessions for a 
particular database user.

If the script is called as root, I re-invoke it as oracle.  However, 'dirname' 
doesn't seem to be working as expect and I have no idea why or how to get 
around it.  A little bit of googl'ing didn't help either so I turn to old 
faithful. :)

#!/bin/sh

export ORAENV_ASK=NO
export ORACLE_SID=xxxxxxx

export SCRIPT=`basename $0`
export SCRIPT_DIR=`dirname $0`

echo "${SCRIPT_DIR} is the script dir."
# Re-invoke this script as oracle if invoked as root
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
if [ "$CUSER" = "root" ]
then
        su - oracle -c "${SCRIPT_DIR}/${SCRIPT}"
        exit $?
fi

<rest of script>

The script output is:

  ". is the script dir."

The script is located in /home/oracle/scripts/sql/topsecret

Anybody know what the deal is?

I'm guessing it has something to do with sub-shells or something but I don't 
know how to work around it.  I guess I can always hardcode the path but I would 
prefer not to.

Thanks for any help!

chris


CONFIDENTIALITY NOTICE:
This message is intended for the use of the individual or entity to which it is 
addressed and may contain information that is privileged, confidential and 
exempt from disclosure under applicable law. If the reader of this message is 
not the intended recipient or the employee or agent responsible for delivering 
this message to the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of this communication is strictly 
prohibited. If you have received this communication in error, please notify us 
immediately by email reply.


Other related posts: