Operating System - HP-UX
1846461 Members
2494 Online
110256 Solutions
New Discussion

Shell command SU destroys script execution

 
Tim Marsh_1
New Member

Shell command SU destroys script execution

I have a shell script that works perfectly, the script basically kills processes based on user ID. As I add the SU - command to the script to change to that user the script bombs. The script uses Korn shell command like for loops etc. The user I switch to .profile indicates the Korn shell. I have added a part of the script below. By the way, I cannot run one script from the other, that is SU and launch another script. The purpose of this script is to be used in SD-UX as a preinstall script of which only one can exist. Any help would be greatly appreciated.


su - ecometry <exitval=0
r=`ps -e | grep exe | grep -v grep | grep -v hello.exe`
if [ ! "$r" = "" ]
then
s=`echo "$r" | awk '{ print $1 }'`
for t in $s
do
echo $t
echo "- PID: $t has been echoed by the user."
done
fi
EO
7 REPLIES 7
Craig Rants
Honored Contributor

Re: Shell command SU destroys script execution

Try using the -c option, i.e.

su - ecometry -c
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
G. Vrijhoeven
Honored Contributor

Re: Shell command SU destroys script execution

Hi Tim,

There are several options:
1. just a check... has the user on all the systems you are planning to install the same UID and GID?

2 put the script in the fileset execute it from configure script and remove it .

3. put all the env settings you will need in the script PATH... etc. and exec an su command.

Hope this will give you some options.

Gideon
James R. Ferguson
Acclaimed Contributor

Re: Shell command SU destroys script execution

Hi Tim:

Unless you are 'root' the 'su' command will require a password to be entered from stdin (as the controlling terminal).

Regardless of this, add the '-c' option to your script as:

su - ecometry -c <...
EOF

Regards!

...JRF...
Tim Marsh_1
New Member

Re: Shell command SU destroys script execution

I've tried the -c option with no luck. Any other ideas???
Roger Baptiste
Honored Contributor

Re: Shell command SU destroys script execution

hi,

Put all the contents between
EOF into a file and call
that file through
su - userid -c "filename"

Remember that the su - will
make the script inherit
the profile settings of
the userid .

HTH
raj
Take it easy.
harry d brown jr
Honored Contributor

Re: Shell command SU destroys script execution

Well I have a big question. if this is a preinstall script for SDux, that is to be run by root, then why do you need to SU??


live free or die
harry
Live Free or Die
Bill Hassell
Honored Contributor

Re: Shell command SU destroys script execution

It's really important to write all scripts with the first line directing which interpreter to use:

#!/usr/bin/ksh

Also, when you are troubleshooting the script, add the trace capability with the command:

set -x

The trace lines always go to stderr so if you want to page through the output, do something like this:

./myscript any-options 2>&1 | pg


Bill Hassell, sysadmin