[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SOLARIS: su - user not passing cmd args



I know this is potentially off-topic, but there doesn't seem to be anything more
than unanswered posts in Sun's support forums on this. And there doesn't seem to
be a Solaris-specific community here in St. Louis, so I'm expanding my search.

On a SOLARIS 8 system, I'm doing the following:

  su - some_user -c 'some_command arg1 arg2 arg3'

However, within the .profile of 'some_user' none of the shells is able to  "see"
the command line arguments passed to it with the '-c' option.

From 'man ksh':

  Invocation
     If the shell is invoked by exec(2), and the first  character
     of  argument zero ($0) is -, then the shell is assumed to be
     a login shell and commands are read  from  /etc/profile  and
     then  from  either  .profile  in  the  current  directory or
     $HOME/.profile, if either file exists.  Next,  commands  are
     read  from  the file named by performing parameter substitu-
     tion on the value of the environment  variable  ENV  if  the
     file exists.  If the -s flag is not present and arg is, then
     a path search is performed on the first arg to determine the
     name of the script to execute. The script arg must have read
     permission and  any  setuid  and  setgid  settings  will  be
     ignored.   If  the  script  is not found on the path, arg is
     processed as if it named a builtin command or function. Com-
     mands  are then read as described below; the following flags
     are interpreted by the shell when it is invoked:

     -c     Read commands from the  command_string  operand.  Set
           the value of special parameter 0 from the value of the
           command_name operand  and  the  positional  parameters
           ($1, $2, and so on) in sequence from the remaining arg
           operands. No commands will be read from  the  standard
           input.

However, when I have a user's .profile set to the following:

  :
  # /bin/ksh
  echo '$_=' $_
  echo '$-=' $-
  echo "dollar-star:" $*
  echo "dollar-at:" "$@"
  echo "dollar-0: $0"
  echo "dollar-1: $1"
  echo "dollar-2: $2"

and I execute the following: 

  su - some_user -c 'ls -ld /tmp'

I get the following:

  $_= :
  $-= sc
  dollar-star:
  dollar-at:
  dollar-0: -ksh
  dollar-1:
  dollar-2:
  drwxrwxrwt   3 root     sys          394 Sep 29 13:44 /tmp

So, the command is executing, but the .profile knows nothing about it.

The reason I want to do this is to detect when I am executing the default 
login shell for the user (which is ksh, not bash), I'd like to switch to
using bash. I do not have control over the default user's shell, hence the
use of the .profile to "switch" to bash.

When I use the command:

  exec /usr/bin/bash --login "$@"

in the .profile after detecting a login shell (i.e. -ksh was invoked or the 
"-c" option is detected via "$-"), because no parameters are passed to the
shell, there is nothing to pass to the replacement bash shell.

So the shell switch occurs, but drops to a command prompt, and does not
execute the given command.

Can anyone else with Solaris duplicate this or (even better) offer an solution?

Mike/

---------------------------------------------
http://www.valuenet.net



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.