Pass the password to su in shell script

Hello,

I am using below command but this is asking for tty

c42dba {/home/oracle}: echo sersnp |  su -c  ggs
standard in must be a tty

Best regards,
Vishal

How about :

su - <user> -c <command>

As for passing password, you will need to use expect or use sudo.
With sudo the syntax is a bit different.

Hope that helps
Regards
Peasant.

1 Like

The sudo tool is designed to give you the choice. It is probably the best way.

Incidentally, you should not really try to force the password in like this. If you have a process to run that is automated, i.e. you don't fire it off as a real person on the command line, then you should really run it as a non-personal account. You can then give that account the sudo privilege to not require a password.

The problem is that if you script this, then anyone able to read your script will know the account password. Additionally, good practice would have you changing the passwords regularly and that might require editing every script each time.

How far have you got with this now?

Kind regards,
Robin

1 Like

It is possible on a lot of systems to create an account that will login without requiring a password. DO NOT fall into that trap. @peasant and @rbatte1 gave you sound advice, consider that doing anything else defeats system security.

2 Likes

We have been doing this using OEM(oracle monitoring tool) .There we can login to each target(host) in the group with ggs user
Here my main target was to first login with oracle user and see if that's a goldengate server(with various customized script under oracle user in all servers) if not then exit out of loop so I was looking to su to ggs from oracle user if that's a golden gate.

Then,we thought that if the server won't be goldengate then ggs user also won't exist which would happen in 99% cases.

Sorry,I am putting more terms as oracle specific.

Best regards,
Vishal