Operating System - HP-UX
1755538 Members
3716 Online
108835 Solutions
New Discussion юеВ

Maintain su'd user during script?

 
SOLVED
Go to solution
Jeff Crump
Occasional Contributor

Maintain su'd user during script?

I am attempting to su to a user (su - prandall) within a script but when I look at the output (> /home/prandall/log.txt) the next command (whoami) after the su does not appear to be executed by prandall. The system shows a logout.

How do I maintain the su'd user during the entire script?

Thanks,

Jeff
4 REPLIES 4
Patrick Wallek
Honored Contributor
Solution

Re: Maintain su'd user during script?

You don't.

The better thing to do would be to write a separate script with the commands you want to run as the prandall user. Then execute that script like this:

su - prandall -c scriptname
Pete Randall
Outstanding Contributor

Re: Maintain su'd user during script?

The answer is obvious: because I didn't execute it!!

;^)


prandall

Pete
Jeff Crump
Occasional Contributor

Re: Maintain su'd user during script?

Patrick:

Thanks, I had seen that kind of reference before ... this helped a lot. However, I do have a follow-up question:

The script I am calling contains the following:

#!/bin/sh

# Look at what kind of file is being transferred and execute the appropriate compile command

case "$vcsfile_suffix" in
".qks") qd $vcsfile;;
".cob") sc_cobcomp $vcsfile;;
esac

fi

exit 0

Aside from the fact that I don't see a new object file being created (I'm transferring a .qks file and the qd command is supposed to do a compile and write an object) how can I get a copy of what is happening within the script to see WHY my new object isn't being created.

The qd command works from the command line if you enter the file name after it and I know the system I calling the script from is passing the $vcsfile variable.

Thanks,

Jeff
Patrick Wallek
Honored Contributor

Re: Maintain su'd user during script?

Try something like this:

su - prandall -c command > logfile 2>&1