Operating System - HP-UX
1836462 Members
2105 Online
110101 Solutions
New Discussion

Re: su -c within a script

 
SOLVED
Go to solution
Coolmar
Esteemed Contributor

su -c within a script

Hi,

I have a user who needs to su to another userid to run a command within a script. However, the user is non-root and therefore, a password is required. The problem is that su will not run from a script because it is interactive and therefore you have to physically type the password. I was thinking of SUDO, but they don't need to run the program as root. Any ideas?

BTW, this is required because the user needs to change to the other userid to run the file because of the profile.
6 REPLIES 6
Peter Godron
Honored Contributor
Solution

Re: su -c within a script

Sally,
not sure about this, but would setting the sticky bit help?
Also chmod the file to allow user 1 to run the file.
Regards
Rajeev Tyagi
Valued Contributor

Re: su -c within a script

sally,

What is the issue with sudo. You are not executing your program as root. If you do sudo su - user2 -c "program" your effective user id is user2 not root.

Steven E. Protter
Exalted Contributor

Re: su -c within a script

root is the only user that can do a su - and not be prompted for an interactive password.

You will need to look at sudo to handle your requirement as written without being prompted for a password.

It is possible to hardcode passwords into scripts, but thats a very bad idea from th security standpoint.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
RAC_1
Honored Contributor

Re: su -c within a script

You can use except tool for it.
Get it here - http://hpux.connect.org.uk
There is no substitute to HARDWORK
Peter Nikitka
Honored Contributor

Re: su -c within a script

Hi,

if you need just entries out of the environment of that other user, these should be transferred to a seperate script (e.g. set.env). Then they can be sourced by every user who needs them (". set.env" for Bourne-like or "source set.env" for CSH-like Shells).

If there are other reason to switch to another user from a non-root account, you can try to replace the 'su' by 'rsh localhost' or 'ssh localhost'. These commands can easily be setup to lack the need of entering a password.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Coolmar
Esteemed Contributor

Re: su -c within a script

Setup SUDO and it worked like a charm. Thanks!