Operating System - HP-UX
1838665 Members
5235 Online
110128 Solutions
New Discussion

Re: run a script by some other user

 
SOLVED
Go to solution
boomer_2
Super Advisor

run a script by some other user

Hi guys,
I have a script owned by xyz and i would like to run it from hash prompt by the user root.

how do i do this ,the current state of the script is ;
-rwsr-xr-x 1 xyz sr 177 Jun 22 10:14 gchk.sh
17 REPLIES 17
Ralph Grothe
Honored Contributor

Re: run a script by some other user

# su - xyz -c /path/to/gchk.sh
Madness, thy name is system administration
boomer_2
Super Advisor

Re: run a script by some other user

Hi Ralph,
I would like to run that script in background.
Dennis Handly
Acclaimed Contributor

Re: run a script by some other user

Since it is a SUID script, why can't you just execute the script as is?
Ralph Grothe
Honored Contributor

Re: run a script by some other user

As root add your xyz user to /var/adm/cron/at.allow
su to xyz and simply issue
$ echo /path/to/gchk.sh | batch
Madness, thy name is system administration
boomer_2
Super Advisor

Re: run a script by some other user

Hi Dennis,
Actually everyday all the processes owned by that user gets killed, so i need to run that script as root user...in backgriuond so that once its run it never gets killed..by using nohup
Ralph Grothe
Honored Contributor

Re: run a script by some other user

Oh, now you revealed that you want this script executed with root suid privileges.
Then besides setting the user sbit (chmod u+s ...) you need to chown root the file.
But be careful, generally one should avoid suid executables.
Madness, thy name is system administration
Dennis Handly
Acclaimed Contributor

Re: run a script by some other user

>so i need to run that script as root user

Then you need to make a copy of that script and remove the SUID bit.
boomer_2
Super Advisor

Re: run a script by some other user

Hi Ralph,
But changing th ownership of the file from xyz to root,the script wont be executed as owner xyz...right
boomer_2
Super Advisor

Re: run a script by some other user

hi Dennis,
Then you need to make a copy of that script and remove the SUID bit.

I wnat to run a script as user/owner of that script " xyz " but the script should be executed by root user..
Dennis Handly
Acclaimed Contributor

Re: run a script by some other user

>I want to run a script as user/owner of that script "xyz" but the script should be executed by root user.

You can't be both at the same time. The script has SUID so no matter who runs it, the user is the script owner.

Looking at ps, I see the script owner in the UID field.

To put in the background, just add "&".

>Ralph: generally one should avoid suid executables.

On 11.23, the default is to disallow them:
secure_sid_scripts 1 1 Immed
boomer_2
Super Advisor

Re: run a script by some other user

Hi Dennis,
When i run the script as root user and then when i do ps -ef|grep ch i get;

root 431 14492 4 13:12:38 pts/24 0:00 sh ./chk.sh
And uid is root and not my "xyz " user.
boomer_2
Super Advisor

Re: run a script by some other user

Hi Dennis,
When i run the script in background as root user and then when i do ps -ef|grep ch i get;

root 431 14492 4 13:12:38 pts/24 0:00 sh ./chk.sh
And uid is root and not my "xyz " user.
boomer_2
Super Advisor

Re: run a script by some other user

Hi ALL,
Script to run in background:
-rwsr-xr-x 1 xyz sr 177 Jun 22 10:14 gchk.sh

FROM ROOT PROMPT BY ROOT USER ONLY WITH NOHUP option.

Regards,
Boomer
boomer_2
Super Advisor

Re: run a script by some other user

Hi ALL,
Script to run in background:
-rwsr-xr-x 1 xyz sr 177 Jun 22 10:14 gchk.sh

FROM ROOT PROMPT BY ROOT USER,BUT MUST SHOW USER -ID AS " xyz " ( in ps -ef|grep gchk ) ONLY WITH NOHUP option.

Regards,
Boomer
Dennis Handly
Acclaimed Contributor
Solution

Re: run a script by some other user

>When i run the script in background as root user and then when i do ps -ef|grep ch i get;

That's not what I get on 11.23 when I enable SUID scripts. And I see no difference when I use nohup.

I am using a SUDO executable to be root.
boomer_2
Super Advisor

Re: run a script by some other user

Hi Dennis,
I too have hpux 11i v2 i.e. 11.23 O.s.
but as i have mentioned my problem.in the previous post,please suggest me any further solution.
Dennis Handly
Acclaimed Contributor

Re: run a script by some other user

Ok I created an alternate root login. That seems different than using SUDO.

No matter what I did, the UID listed in ps was root.

The documentation says that ps returns the real user ID in UID. So perhaps everything is working after all?

Hmm, it seems that ps works differently. If you use -ef and grep you see the effective ID.

But if you use -fu, you get the real ID.

Ah, if you use UNIX95=, you get the effective ID. And that's what's documented!
+ The -u option will select users based on effective UID rather than real UID.

So this may be how you can stop it from being killed.