Operating System - HP-UX
1829125 Members
2276 Online
109986 Solutions
New Discussion

How to pass password to "su" as a parameter within a shell script?

 
SOLVED
Go to solution
Binu Raj
Occasional Contributor

How to pass password to "su" as a parameter within a shell script?

Hi All

I need to add an entry to the /etc/services file while running a shell script as a normal user. But I don't want su to prompt me for the root password instead it can be passed on to the shell script by a GUI interface(I can make this interface not to display the password). Or I can accept the password as an argument to the script.

The shell script can add desired entries to the services file and then exit.

Can somebody out there help me?

Thanks in advance

Regards

Binu
4 REPLIES 4
Steve Steel
Honored Contributor

Re: How to pass password to "su" as a parameter within a shell script?

Hi

Try sudo

A method of using root commands is with the program called sudo. Information is available at:

www.courtesan.com/sudo/

Please note that Hewlett-Packard does not support sudo.


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Massimo Bianchi
Honored Contributor
Solution

Re: How to pass password to "su" as a parameter within a shell script?

Otherwise implement a script with ssh, which is hp supported:

http://www.software.hp.com/cgi-bin/swdepot_parser.cgi/cgi/displayProductInfo.pl?productNumber=T1471AA

or


create a setuid executable, whose only function is to add/remove that service.

Massimo

RAJESH GANGADHARAN
Regular Advisor

Re: How to pass password to "su" as a parameter within a shell script?

Hi
You can download a thirdparty tool called expect using this you can pass the password to su or password command.

-Rajesh
Let the choices you make today be the choices you can live with tomorrow.
RolandH
Honored Contributor

Re: How to pass password to "su" as a parameter within a shell script?

Do somthing like that

Create a little script that belongs to root and group admin ( for example ). your user belongs to group admin, too. This little script will add your line to /etc/services.

Then set the s-Bit on that script.
#ll myscript.sh
-rw-r--r-- 1 root admin 123 Jul 24 10:55 myscript.sh

#chmod 550 myscript.sh
# chmod g+s myscript.sh
#ll myscript.sh
-r-xr-s--- 1 root admin 123 Jul 24 10:55 myscript.sh

And now you can use this script in your main script.


Roland

Sometimes you lose and sometimes the others win