0

Im finding trouble writing a script that runs from account A, switches user to B (on same server), performs a few jobs at B, and switches back to A. I want the password for B hardcoded in the script so that it doesnt prompt for one. Someone please help.

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by alc6379
0

Hardcoded passwords are a security risk - FWIW.

if you are root you can use sudo or su by default. Otherwise use a here document:

su username <<!
password
/bin/ksh
command 
command 
command
exit
!

su may also give you the wrong shell, which is why I put "/bin/ksh" in there.

0

Thanks, Jim. But it still prompts for a password just after "su username" command. Any way we could hardcode this? And none of the accounts is a superuser. Anyone?

0

I'm going to have to agree with Jim on this one. You really should look into setting up sudo for something like this.

If you know the user that's going to run it, and you know the username ahead of time, then you can set up the appropriate permissions in /etc/sudoers, and not have to worry about a password at all.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.