1828682 Members
2231 Online
109984 Solutions
New Discussion

HPUX

 
SOLVED
Go to solution
Raymond Fournier
Occasional Contributor

HPUX

I have three scripts, script A owned by user A and script B owned by user B. How can root execute these scripts as the owner.
Green
9 REPLIES 9
harry_7
Frequent Advisor

Re: HPUX

Hi,

I think you have to play with CHMOD/CHOWN command

Regards

Harry
A. Clay Stephenson
Acclaimed Contributor

Re: HPUX

Root can use the su command to switch user. Man su for details. Note that the effective UID is changed not the UID.
If it ain't broke, I can fix that.
Justo Exposito
Esteemed Contributor
Solution

Re: HPUX

Hi Raymond,

Try with:

su - userb -c "/path/yourscriptname"

Regards,

Justo.
Help is a Beatiful word
Jeanine Kone
Trusted Contributor

Re: HPUX

When I want root to execute scripts as my oracle user I do:

su oracle -c "full_path_and_script parameters"

Jeanine
V. V. Ravi Kumar_1
Respected Contributor

Re: HPUX

hi,

su - -c "script path"

regds
Never Say No
Hai Nguyen_1
Honored Contributor

Re: HPUX

Root as user A

# su - A -c full_path_name_of_user_A_script

And root as user B:

# su - B -c full_path_name_of_user_B_script

Hai
Nick Wickens
Respected Contributor

Re: HPUX

How about using the file permissions set userid options -

For example create a script called say ownerx with the line "touch fish".

Now set the owner of the script to UserA (chown userA ownerx).

Now set the permissions to 4700 (chmod 4700 ownerx).

Now as root run the script ownerx and then look at the owner of the file "fish" and it should be UserA.

Hats ? We don't need no stinkin' hats !!
A. Clay Stephenson
Acclaimed Contributor

Re: HPUX

You do need to be aware of the problem of using su - username as opposed to su username (no dash). The dash says user username's .profile so that all environment variables are set. They may be a very good thing but if these scripts are run in a non-interactive environment, they will almost ceratinly fail. The .profile usually contain commands to query stdin's terminal or to write to it (e.g. tset, stty, tabs, ...). The best solution is to create a file (e.g. /usr/local/bin/oraenv.sh) that sets and exports any needed env vars and then both your scripts AND username's .profile should source this file. There must be no exit or return statements in this file.

. /usr/local/bin/oraenv.sh

You then do an su username and your script runs as expected.
If it ain't broke, I can fix that.
Misa
Frequent Advisor

Re: HPUX

One tiny point about how UNIX works: even though script A is owned by user A, it's not necessary for root to "become" user A in order to run script A.

If the permissions are set correctly, root has the potential to run anything. (Now for security reasons, you may not *want* root to run it, but that's another story.)

For example, if script A is like this (ls -l scriptA):

-rwxr-xr-x userA users .... scriptA

root can run the script. It will be run as root, though. The command to get it to look like the above example would be (done as root or as userA):

chmod 755 scriptA

(If you've never seen it, the chmod command also has a "symbolic" mode that makes it much easier to remember.)

Sorry if this was all old news. I was going on the comment in your forums profile. :)

--Misa