Re: basic bash help
From: David Fitzjarrell <oratune_at_yahoo.com>
Date: Fri, 27 May 2011 12:10:29 -0700 (PDT)
Message-ID: <180737.8741.qm_at_web65404.mail.ac4.yahoo.com>
Date: Fri, 27 May 2011 12:10:29 -0700 (PDT)
Message-ID: <180737.8741.qm_at_web65404.mail.ac4.yahoo.com>
And you are correct, setting '.' in the path doesn't return '.' as the directory name. I said that with the untested assumption that it would. I won't do that again. :) Calling the script in this manner does return '.' as the directory name: ./<scriptname> $ envtest.sh /export/home/dfitzjarrell-admin/bin is the script dir. $ ./envtest.sh . is the script dir. David Fitzjarrell ________________________________ From: "Stephens, Chris" <Chris.Stephens_at_adm.com> To: David Fitzjarrell <oratune_at_yahoo.com> Sent: Fri, May 27, 2011 12:00:24 PM Subject: RE: basic bash help Thanks, but I don’t think that’s it: [root_at_050orareddb vmware]# cat kill_vm.sh #!/bin/sh export ORAENV_ASK=NO export ORACLE_SID=yyyyy 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> [root_at_xxxxxxx ]#./kill_vm.sh . is the script dir. PATH: /bin:/jdk/jre/lib/i386/server:/rdbms/lib:/lib:/usr/lib:/usr/X11R6/lib:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/sbin:/usr/sbin:/root/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/home/oracle/bin:/u01/app/oracle/product/11.2.0/dbhome_1/bin -bash: ./kill_vm.sh: No such file or directory [root_at_xxxxxxx ]# From:David Fitzjarrell [mailto:oratune_at_yahoo.com] Sent: Friday, May 27, 2011 1:52 PM To: Stephens, Chris; oracle-l_at_freelists.org Subject: Re: basic bash help Check the path for '.' as that allows running scripts/programs from the current directory, which is where you are when you run the script. If you remove that entry from the path then the 'proper' directory name should appear. David Fitzjarrell ________________________________ From:"Stephens, Chris" <Chris.Stephens_at_adm.com> To: "'oracle-l_at_freelists.org' (oracle-l_at_freelists.org)" <oracle-l_at_freelists.org> Sent: Fri, May 27, 2011 11:42:28 AM Subject: basic bash help 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. J #!/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. 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.
-- http://www.freelists.org/webpage/oracle-lReceived on Fri May 27 2011 - 14:10:29 CDT