Operating System - HP-UX
1830899 Members
1905 Online
110017 Solutions
New Discussion

Re: "su -" hangs when called inside a shell script.

 
Chris Magargee_2
Frequent Advisor

"su -" hangs when called inside a shell script.

We have a master shell script thats calls another shell script that does a:

su - -c "<script> $ARGS"

Periodically when the master script calls the sub script, the "su" will hang. You can see the "su" in a ps, but it is not running.

We can kill the "su", rerun the master script and the "su" from the sub script runs fine.

Any thoughts or suggestions would be greatly appreciated.

Thanks!
Chris
9 REPLIES 9
RAC_1
Honored Contributor

Re: "su -" hangs when called inside a shell script.

Let us isolate the problem first.
su -
Does it work?? If not resolve it and if everything is ok, move on. Run the script.
"<script> $ARGS" Is that OK??
If not check your script.

Put set -vx in script and check what step it failes at. Make sure you run commands with full path names, all required variables are defined.
There is no substitute to HARDWORK
Pedro Cirne
Esteemed Contributor

Re: "su -" hangs when called inside a shell script.

Hi,

Who's running the script? Root?

If it's not root, su will wait for a password.

Enjoy :)

Pedro
Pat Lieberg
Valued Contributor

Re: "su -" hangs when called inside a shell script.

It looks like you're passing a command along with the su. Is it that command that is hanging? Or, does that command never run?
James R. Ferguson
Acclaimed Contributor

Re: "su -" hangs when called inside a shell script.

Hi Chris:

Unless the script issuing the 'su' is running as 'root', 'su' will prompt for a password for the account to which you are attmpting to switch. The problem is that you cannot supply the password except in an interactive way; i.e. redirection from file will not work.

Regards!

...JRF...
Chris Magargee_2
Frequent Advisor

Re: "su -" hangs when called inside a shell script.

To answer some of the questions.

1) It is being run by root.
2) The su command runs by hand works fine.
3) The su itself appears to hang, we never receive the login banner from the "su -".

Thanks!
Chris
Pedro Cirne
Esteemed Contributor

Re: "su -" hangs when called inside a shell script.

Hi,

I think that some environment variable is missing.

Are you running this script from cron?

If you run it from cron you don't have the environement variables defined of the user root and they are not passed to the user when you su to it.

Check:

#man su
#man cron

Enjoy :)

Pedro
Chris Magargee_2
Frequent Advisor

Re: "su -" hangs when called inside a shell script.

Running it from the command line.....
Tim Nelson
Honored Contributor

Re: "su -" hangs when called inside a shell script.

What login banner ? su - may read the new users profile but that is about it other than your command you are telling it to run.

Mel Burslan
Honored Contributor

Re: "su -" hangs when called inside a shell script.

in your scrip, just before the line, running the su command, insert a line

set -x

and right after su line, insert another one containing, guess what:

set +x

and run your script. You may see why and where it stops. If you see the su command getting executed, then try starting your script called from the su command with "set -x" and ending it with "set +x", it will show you the variable assignments made on the fly or what it is waiting for etc.

hope this helps
________________________________
UNIX because I majored in cryptology...