Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Korn shell and Su

Status
Not open for further replies.

Senseial

Programmer
Feb 11, 2004
40
CA
Hello

I need help with something and I am not sure it can be done but you never know.
Working with Unix Korn Shell can I automate a script using su (user_name) send password and execute few commands like pgp a file as that user and exit back to my session. What ever I tried it will sit at Password: . So much for automation. Can I send password and enter command in Korn shell script to accomplish this????
Thank You
 
first few lines:
#!/bin/ksh
su ingenix
expect "Password: "
send "passwordhere\r"

no matter what it sits and is waiting for me to enter password manually?
 
Never mind this will not work. I don't have expect and send installed and they will not install this anyway. I need to work with echo. I am not sure if this can be done.
Thanks anyway
 
You can't use [tt]echo[/tt] and redirection to give [tt]su[/tt] the password. The command [tt]su[/tt] doesn't use [tt]stdin[/tt] to take in the password, it opens and reads from [tt]/dev/tty[/tt], which you can't redirect to/from. I believe "[tt]expect[/tt]" is your only option.
 
You can use [tt]ssh[/tt] to run a script as another user without having to supply a password. It would look like...
Code:
#!/bin/ksh

ssh ingenix@localhost "command"
You'd have to share the public key first. There are a number of threads here on Tek-Tips that explain how to set it up.
 
Hi

I would still use [tt]sudo[/tt]. [tt]ssh[/tt] is a workaround, [tt]sudo[/tt] was invented for this situation.
sudo.ws said:
Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments.

Feherke.
 
Thank you guys. I will try ssh, but I am not sure if it will work. as for sudo they will not allow. I know that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top