Operating System - HP-UX
1837341 Members
3448 Online
110116 Solutions
New Discussion

How to switch users in a script file automatically?

 
SOLVED
Go to solution
Thomas Qiang
New Member

How to switch users in a script file automatically?

Hi, there,
How can I switch from one account to another using "say SU - USER -C .." wothout being prompted for passwd interactively?
Currently we use "Autosys" to start/stop a batch process that must be run in a specific user account.
I will summarize all the answers and post it later.
Thank you for your help
A picture is worth of one thousand words
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: How to switch users in a script file automatically?

Hi Thomas:

In a simple shell script, you cannot issue and 'su' and avoid the interactive prompt.

...JRF...
Pedro Sousa
Honored Contributor

Re: How to switch users in a script file automatically?

Hi Thomas,
from the man pages:
"To use su, the appropriate password must be supplied unless the current user is superuser."

maybe "Sudo" can help you on giving superuser permissions on some commands to some users.
I've never tried it for this kind of problems.
good luck.
Lawrence Mahan
Frequent Advisor

Re: How to switch users in a script file automatically?

I had the same problem. What I did was to write a C routine that used the setuid and setgid functions. The compiled executable then needs to be owned by root before the command will switch to another user. You must turn off the write bit or you will have a security hole in your system.
Vincenzo Restuccia
Honored Contributor

Re: How to switch users in a script file automatically?

If you run the script with id=root:
su - user -c command
Jerry Jordak
Advisor
Solution

Re: How to switch users in a script file automatically?

Would it be possible in your environment to change the job definition in AutoSys to have it run as the user you need it to run as? You can specify the user to run the job as when you create the job. That would eliminate the need to do an "su".