AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  How to run a script involves two users

    Posted 01/30/07 04:47 PM

    Originally posted by: SystemAdmin


    I tried to write a script that will run commands in two different user scopes. Here is my draft, but it only run in the first user -root, but not the second user - oracle.
    impDB.sh:
    cd /ora_import/dump
    chmod o+r expBaan201.dmp*
    mv expBaan201.dmp* expBaan201.dmp
    su - oracle
    pwd >> /ora_import/dump/impMessage.log
    $PATH >> /ora_import/dump/impMessage.log
    impdp ...

    I run manually from root and in a crontab job, none of them ever switch to user - oracle scope beacuse pwd command showed I was still in the /ora_import/dump and the $PATH was still the original PATH of root, not the oracle, therefore it could not find the impdp. What I missed? I tried to include "<<EOF" or <<!" in the end of su - oracle, but not work.
    #AIX-Forum


  • 2.  Re: How to run a script involves two users

    Posted 01/30/07 05:05 PM

    Originally posted by: orphy


    Since you have a few lines to run as the oracle user, why not just put all
    those commands in a script and call it whatever.ksh then you can fix impDB.sh
    to something like:

    cd /ora_import/dump
    chmod o+r expBaan201.dmp*
    mv expBaan201.dmp* expBaan201.dmp
    su - oracle -c "/path-to/whatever.ksh"

    Just make sure whatever.ksh is executable and possibly owned by oracle.

    I'm curious though. Why can't you run the whole thing as oracle? Are there
    any reasons why the dumps are not owned by oracle or that /ora_import/dump is
    owned by root?

    And I'm a bit confused about this: mv expBaan201.dmp* expBaan201.dmp. Maybe
    I'm not seeing the whole picture...
    Orphy
    #AIX-Forum


  • 3.  Re: How to run a script involves two users

    Posted 01/30/07 06:56 PM

    Originally posted by: SystemAdmin


    Thanks Orphy, you help me a lot for many subjects on the AIX. Speeding up my learning of the AIX.
    Yes, I did skipped out some details from post.
    1. first the expBaan201 file was created on other machine under the root. So when it passed to this box, user oracle can not handle it unless I chmod and switch.
    2. the expBaan201 was created automatically daily labelled with timstamp, where the * stands for. so I have to mv it to the expBaan201.dmp, which the oracle impdp program will accept.
    3. Actully you are right, I can put the oracle home path in root so i can run the whole thing in root or as you said changing the /dump dir to oracle:oinstall so run the whole thing in oracle ( what I was thinking)
    4. I just want to test the water how thing is running with different users within a script.
    #AIX-Forum


  • 4.  Re: How to run a script involves two users

    Posted 01/30/07 09:49 PM

    Originally posted by: orphy


    Two comments. It's best to run as many things as non-root user as possible so
    as to eliminate possible problems since root is way too powerful and certain
    carelessness could be quite destructive. Secondly, for point 2, be care that
    the mv could cause problems if you have more than one expBaan201<timestamp>
    files in there, say a stale one from the previous run.

    Another idea is that if you have control of the script that copies the dmp over,
    you could consider doing a chmod/chown after the file transfer so that you could
    eliminate using root altogether.
    Orphy
    #AIX-Forum


  • 5.  Re: How to run a script involves two users

    Posted 02/01/07 01:07 PM

    Originally posted by: SystemAdmin


    Maybe I can do the chown on my source side, so I can use the oracle user instead of root on the destined side. eliminate the involvement of root for all. Thanks.
    #AIX-Forum