[comp.unix.xenix.sco] whoami?

jca@pnet01.cts.com (John C. Archambeau) (12/04/90)

Is there a version of the who command for Xenix that will give you your
effective user id when presented with who am i?

Say I'm logged in as myself and do an su to become root.  Well, who am i
returns your line in the /etc/utmp file.  What I want is more along the lines
of who I am now.  Is there a version of who that does this?

 Thanks,

     // JCA

 /*
 **--------------------------------------------------------------------------*
 ** Flames  : /dev/null                     | What to buy?
 ** ARPANET : crash!pnet01!jca@nosc.mil     | EISA or MCA?
 ** INTERNET: jca@pnet01.cts.com            | When will the bus wars end?
 ** UUCP    : {nosc ucsd hplabs!hp-sdd}!crash!pnet01!jca
 **--------------------------------------------------------------------------*
 */

paulz@sco.COM (W. Paul Zola) (12/24/90)

In article <6066@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
}Is there a version of the who command for Xenix that will give you your
}effective user id when presented with who am i?
}
[deleted]

I suggest you look at the id(C) command.  It might just do what you want.


	lanshark@p2 [~]
	[1]: id
	uid=666(paulz) gid=115(support)

	lanshark@p2 [~]
	[2]: su root
	Password:
	# id
	uid=0(root) gid=1(other)
	# exit

	lanshark@p2 [~]
	[3]:

Hope this helps.

-
Paul Zola			Software Support Engineer 
				paulz@sco.COM 
We only know in theory what we are doing.   - Kate Bush
    DISCLAIMER: I speak for myself, and not for SCO.

jca@pnet01.cts.com (John C. Archambeau) (12/26/90)

paulz@sco.COM (W. Paul Zola) writes:
>
>In article <6066@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>}Is there a version of the who command for Xenix that will give you your
>}effective user id when presented with who am i?
>}
>[deleted]
>
>I suggest you look at the id(C) command.  It might just do what you want.
>
>
>	lanshark@p2 [~]
>	[1]: id
>	uid=666(paulz) gid=115(support)
>
>	lanshark@p2 [~]
>	[2]: su root
>	Password:
>	# id
>	uid=0(root) gid=1(other)
>	# exit
>
>	lanshark@p2 [~]
>	[3]:
>
>Hope this helps.
>
>-
>Paul Zola			Software Support Engineer 
>				paulz@sco.COM 
>We only know in theory what we are doing.   - Kate Bush
>    DISCLAIMER: I speak for myself, and not for SCO.


What I want is something similiar to the BSD/SunOS whoami.  For example, in a
.cshrc file, I want to be able to do this:

if (`whoami` == "root") then
 set prompt = "#"
else
 set prompt = "%"
endif

Something like that.  Somebody gave me a code fragment in e-mail that does
return what I want, but shell scripts bomb.  Any idea why?


     // JCA

 /*
 **--------------------------------------------------------------------------*
 ** Flames  : /dev/null                     | What to buy?
 ** ARPANET : crash!pnet01!jca@nosc.mil     | EISA or MCA?
 ** INTERNET: jca@pnet01.cts.com            | When will the bus wars end?
 ** UUCP    : {nosc ucsd hplabs!hp-sdd}!crash!pnet01!jca
 **--------------------------------------------------------------------------*
 */

jfh@rpp386.cactus.org (John F Haugh II) (12/27/90)

In article <6537@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>What I want is something similiar to the BSD/SunOS whoami.  For example, in a
>.cshrc file, I want to be able to do this:
>
>if (`whoami` == "root") then
> set prompt = "#"
>else
> set prompt = "%"
>endif
>
>Something like that.  Somebody gave me a code fragment in e-mail that does
>return what I want, but shell scripts bomb.  Any idea why?

Try something like this -

% id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'
jfh

which would give you -

if ( `id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'` == "root" ) then
	set prompt = "#"
else
	set prompt = "%"
endif
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
"While you are here, your wives and girlfriends are dating handsome American
 movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."

davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (12/28/90)

In article <6537@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:

| if (`whoami` == "root") then
|  set prompt = "#"
| else
|  set prompt = "%"
| endif
| 
| Something like that.  Somebody gave me a code fragment in e-mail that does
| return what I want, but shell scripts bomb.  Any idea why?

  Because it sets the prompt for the shell running the script and all
commands run by it, but not in the environment of the interractive
shell. You need to run the shell script with '.' or put it in the .profile.
-- 
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me

jca@pnet01.cts.com (John C. Archambeau) (12/29/90)

davidsen@sixhub.UUCP (Wm E. Davidsen Jr) writes:
>In article <6537@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>
>| if (`whoami` == "root") then
>|  set prompt = "#"
>| else
>|  set prompt = "%"
>| endif
>| 
>| Something like that.  Somebody gave me a code fragment in e-mail that does
>| return what I want, but shell scripts bomb.  Any idea why?
>
>  Because it sets the prompt for the shell running the script and all
>commands run by it, but not in the environment of the interractive
>shell. You need to run the shell script with '.' or put it in the .profile.
>-- 
>bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
>    sysop *IX BBS and Public Access UNIX
>    moderator of comp.binaries.ibm.pc and 80386 mailing list
>"Stupidity, like virtue, is its own reward" -me


Wait a minute.  Doesn't the .cshrc apply to the C-Shell being started up and
affects the environment of the started C-Shell?  I know this is the case for
BSD/SunOS.  Is this just an idiosyncrasy of the Xenix C-Shell?


     // JCA

 /*
 **--------------------------------------------------------------------------*
 ** Flames  : /dev/null                     | What to buy?
 ** ARPANET : crash!pnet01!jca@nosc.mil     | EISA or MCA?
 ** INTERNET: jca@pnet01.cts.com            | When will the bus wars end?
 ** UUCP    : {nosc ucsd hplabs!hp-sdd}!crash!pnet01!jca
 **--------------------------------------------------------------------------*
 */

edhew@xenitec.on.ca (Ed Hew) (12/30/90)

In article <18865@rpp386.cactus.org> jfh@rpp386.cactus.org (John F Haugh II) writes:
>
>if ( `id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'` == "root" ) then
>	set prompt = "#"
>else
>	set prompt = "%"
>endif
>-- 
>John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
>Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org

Unless I'm missing something, why not simply

if ( `logname` == "root" ) then

	....and so on?
--
  Ed. A. Hew  <edhew@xenitec.on.ca>,  XeniTec Consulting Services
  or if you're really stuck:  ..!{watmath|lsuc}!xenitec!eah

jca@pnet01.cts.com (John C. Archambeau) (12/31/90)

edhew@xenitec.on.ca (Ed Hew) writes:
>Unless I'm missing something, why not simply
>
>if ( `logname` == "root" ) then
>
>	....and so on?

Because logname returns exactly that, your login name.  If you do an su to
root and do a logname it will return the login name of the account you logged
in as not root.

What I want is something that will tell me the login name of the effective
user id.  I haven't tried the code fragment with sed yet, but I did try your
suggestion out and it doesn't work.

I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
both the Bourne and C Shells.

     // JCA

 /*
 **--------------------------------------------------------------------------*
 ** Flames  : /dev/null                     | What to buy?
 ** ARPANET : crash!pnet01!jca@nosc.mil     | EISA or MCA?
 ** INTERNET: jca@pnet01.cts.com            | When will the bus wars end?
 ** UUCP    : {nosc ucsd hplabs!hp-sdd}!crash!pnet01!jca
 **--------------------------------------------------------------------------*
 */

betz@marob.uucp (Tom Betz) (01/01/91)

Quoth jfh@rpp386.cactus.org (John F Haugh II) in <18865@rpp386.cactus.org>:
|From: article <6537@crash.cts.com> :
|>What I want is something similiar to the BSD/SunOS whoami.  For example, in a
|>.cshrc file, I want to be able to do this:
|>
|>if (`whoami` == "root") then
|> set prompt = "#"
|>else
|> set prompt = "%"
|>endif
|>
|
|Try something like this -
|
|% id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'
|jfh
|
|which would give you -
|
|if ( `id | sed -e 's/^[^(]*(\([^)]*\)).*$/\1/'` == "root" ) then
|	set prompt = "#"
|else

FWIW, Here's the ksh version, removed from my .kshrc:
 
 MYPROMPT=""
 if /bin/id | /bin/grep "uid=0" > /dev/null
  then	MYPROMPT="#"
 fi
 MYPROMPT=${MYPROMPT}`/bin/tty | /usr/bin/cut -c9,10`
 PS1='$MYPROMPT ! $PWD> '
 export PS1
   
This has the added benefit of displaying the current tty# and ksh
history counter, as well as the cwd and a different symbol for
root or non-root user.

-- 
--------------           "Healt ut industri di go hond-e-hond."
Tom Betz     | -----------------------------------------------------------------
914-375-1510 | marob!upaya!tbetz@phri.nyu.edu betz@marob.uucp%phri.nyu.edu
GBS          | {att,philabs,rutgers,cmcl2}!phri!marob!upaya!tbetz

mrm@sceard.Sceard.COM (M.R.Murphy) (01/02/91)

In article <6624@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>
>I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
>both the Bourne and C Shells.
>
>     // JCA

You could always try 

 $ who am i

like it says in the manual :-)
-- 
Mike Murphy  mrm@Sceard.COM  ucsd!sceard!mrm  +1 619 598 5874

mpd@anomaly.sbs.com (Michael P. Deignan) (01/02/91)

From: article <6537@crash.cts.com> :
>What I want is something similiar to the BSD/SunOS whoami.  For example, in a
>.cshrc file, I want to be able to do this:
>
>if (`whoami` == "root") then
> set prompt = "#"
>else
> set prompt = "%"
>endif

UUCP: anomaly!~/bsd/whoami.tar.Z <yourfile>

This is the whoami program from the BSD sources slightly modified to work
under XENIX. It will compile into "whoamireally", which you can use in your
script.

Consult the SCO Ported Software Compendium for appropiate anonymous UUCP
information.

MD

-- 
--  Michael P. Deignan                      / Sex is hereditary. If your 
--  Domain: mpd@anomaly.sbs.com            /  parents never had it, chances 
--    UUCP: ...!uunet!rayssd!anomaly!mpd  /   are you won't either...
-- Telebit: +1 401 455 0347              /

jfh@rpp386.cactus.org (John F Haugh II) (01/02/91)

In article <1990Dec30.080938.21103@xenitec.on.ca> edhew@xenitec.on.ca (Ed Hew) writes:
>Unless I'm missing something, why not simply
>
>if ( `logname` == "root" ) then

logname doesn't say who you are =now=.  the results
of logname will be incorrect if you are su'd to/from a
different user id.  id always reports your current
user name.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
"While you are here, your wives and girlfriends are dating handsome American
 movie and TV stars. Stars like Tom Selleck, Bruce Willis, and Bart Simpson."

jca@pnet01.cts.com (John C. Archambeau) (01/04/91)

mrm@sceard.Sceard.COM (M.R.Murphy) writes:
>In article <6624@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>>
>>I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
>>both the Bourne and C Shells.
>You could always try 
>
> $ who am i
>
>like it says in the manual :-)

I don't know if you're being funny or not.  All who am i does is return your
entry in /etc/utmp.  This may not be your effective login user name.
Case and point, logging in and executing an su, effective login name being
root.

     // JCA

 /*
 **--------------------------------------------------------------------------*
 ** Flames  : /dev/null                     | What to buy?
 ** ARPANET : crash!pnet01!jca@nosc.mil     | EISA or MCA?
 ** INTERNET: jca@pnet01.cts.com            | When will the bus wars end?
 ** UUCP    : {nosc ucsd hplabs!hp-sdd}!crash!pnet01!jca
 **--------------------------------------------------------------------------*
 */

schenk@dg.cpsc.ucalgary.ca (Eric Schenk) (01/04/91)

>In article <6624@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>
>I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
>both the Bourne and C Shells.

The GNU bin tools package has a whoami command that seems to be BSD lookalike.
I've compiled it on my machine without problems using gcc, but it's
probably simple enough to use cc as well.

-------------------------------------------------------------------------------
Eric Schenk               Department of Computer Science, University of Calgary
schenk@cpsc.ucalgary.ca   Just another graduate slave.
-------------------------------------------------------------------------------

pavlov@canisius.UUCP (Greg Pavlov) (01/04/91)

In article <1991Jan1.183022.12539@sceard.Sceard.COM>, mrm@sceard.Sceard.COM (M.R.Murphy) writes:
> >
> >I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
> >both the Bourne and C Shells.
> >
> You could always try 
> $ who am i
> like it says in the manual :-)


  Depending on which manual you have:  these are not the same.  "whoami" returns
  the effective user id, not the login id.

   greg pavlov, fstrf, amherst, ny

schenk@fsd.cpsc.ucalgary.ca (Eric Schenk) (01/04/91)

I wrote:
>>In article <6624@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>>
>>I want the equivalent of whoami on BSD/SunOS for SCO Xenix that will work on
>>both the Bourne and C Shells.
>
>The GNU bin tools package has a whoami command that seems to be BSD lookalike.
>I've compiled it on my machine without problems using gcc, but it's
>probably simple enough to use cc as well.

Unfortunatly this is not true.  I noticed in passing that I had whoami
in /usr/local/bin on my system, and for unknown reason I assumed that
it was part of the GNU bin tools distribution.  In fact my copy is
from the BSD free sources, and was distributed as part of the MGR
distribution for xenix.  Since the source is so small I've include
the shar file below.

Enjoy

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  whoami.c
# Wrapped by schenk@cpsc.UCalgary.CA on Thu Jan  3 23:11:35 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'whoami.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'whoami.c'\"
else
echo shar: Extracting \"'whoami.c'\" \(1326 characters\)
sed "s/^X//" >'whoami.c' <<'END_OF_FILE'
X/*
X * Copyright (c) 1988 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1988 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)whoami.c	5.3 (Berkeley) 6/29/88";
X#endif /* not lint */
X
X#include <sys/types.h>
X#include <pwd.h>
X
Xmain()
X{
X	struct passwd *p, *getpwuid();
X	int uid;
X
X	uid = geteuid();
X	if (!(p = getpwuid(uid))) {
X		printf("whoami: no login associated with uid %u.\n", uid);
X		exit(1);
X	}
X	printf("%s\n", p->pw_name);
X	exit(0);
X}
END_OF_FILE
if test 1326 -ne `wc -c <'whoami.c'`; then
    echo shar: \"'whoami.c'\" unpacked with wrong size!
fi
# end of 'whoami.c'
fi
echo shar: End of shell archive.
exit 0
-------------------------------------------------------------------------------
Eric Schenk               Department of Computer Science, University of Calgary
schenk@cpsc.ucalgary.ca   Just another graduate slave.
-------------------------------------------------------------------------------

tony@oha.UUCP (Tony Olekshy) (01/08/91)

I just noticed this thread and consulted the whoami I wrote when I migrated
from System III to Xenix...

	expr "Z`id`" : "Zuid=[0-9]*(\([^)]*\))"

--
Yours etc., Tony Olekshy.       Internet: tony%oha@CS.UAlberta.CA
				  BITNET: tony%oha.uucp@UALTAMTS.BITNET
				    uucp: alberta!oha!tony
He who has nothing to assert has no style and can have none.--Shaw