Running "who am i" on sol 8

Hi All

I have a ksh script, which is run as the root user. At some point in the script, it needs to check for the user that is running the script. ( The real user that su to root). This is on a sol 8 server, but it displays the user as root instead of my username.

root@host-1 # who am i | cut -f1 -d' '
root
root@host-1 #

I tried the same command on a sol 10...

root@host-2# who am i | cut -f1 -d' '
wisdom
root@host-2 #

Does anybody have any idea?
Thanks in advance.

It may not support the 'am I' options and just output like 'who'.

I've just tried it on another sol8 and it worked. So it means it's got to be some setting on host-1 that is making it work abnormally.

The problem is I don't know what to look for?

Do a "truss who am i" on both solaris 8 systems and compare the output to find the difference.

I just compared your code as well and got the correct output.

So... Well... Ok, I'll say it. Are you SURE you didn't log in as root directly?

Sorry, but it had to be asked.

What's the output of this commands (after su to root)?

id -un
id -ur wisdom

try:

/usr/bin/who am i
/usr/xpg4/bin/who am i
/usr/ucb/whoami

If I remember correctly, I think you'll find that /usr/bin/who does not work as "who am i". So place /usr/xpg4/bin in your PATH before /usr/bin. This also affects awk and some other commands.

we've concluded for now that the weirdness of the server must be due to the in-house passwd/authentication application that we use. It's the only server that behaves like that.

Due to policies, I cannot go poking around the server to make changes. So for now.... I rest my case.

Thank you for all contributions.

Why did you start a new thread while you already had one on the very same subject ?

Also, if you want to understand better what's going on on that particular server, please reply to my question in its last posting (#10).

jlliagre

Your question was answered. It's just to display the real user. Just one username. Also, I actually thought it was a scripting problem and I had posted it on the wrong forum.

I don't know how to merge the threads. Maybe a moderator would merge it for me.

Besides, like I said before... it's the only server in the company that behaves that way and due to policies, it's a no-go area.

Anyway, thank you.

I'm afraid it wasn't. Can you please post what returns the "tty" command in addition to what "w" returns.

root@ # ksh
root@ # a=$(tty)
root@# echo $a
/dev/pts/5
root@ #

Sorry if I wasn't clear enough. I'm asking for both of "tty" and "w" outputs during the same shell session.

root@# echo "$w"
  4:02pm  up 195 day(s),  7:50,  1 user,  load average: 5.86, 5.82, 5.72
User     tty           login@  idle   JCPU   PCPU  what
wisdom   pts/1         4:01pm                      w
root@ #
root@ #
root@ # echo $a
pts/5
root@ #

I suspect a corrupted wtmpx file. What says:

ls -lL /etc/wtmpx
last -10

@wisdom
Please answer post #6 (the one about "id" commands).

Answer for post #6

$ id -un
id: illegal option -- u
Usage: id [-ap] [user]
$
$ which id
/usr/bin/id
$

But the output is different when I used this id path:-

$  /usr/xpg4/bin/id -un
$ wisdom
$  /usr/xpg4/bin/id -ur wisdom
1114
$

Now, when I su to root and run the same command, I get the following :-

 root@host # /usr/xpg4/bin/id -un
root
root@host #

@wisdom
Please answer post #15

jlliagre

I suspect that also. Answer for post #15 :-

$ ls -lL /etc/wtmpx
-rw-r--r--   1 root     other    267327384 Mar 28 10:55 /etc/wtmpx
$
$
$ last -10
app-user   ftp          app-host         Mon Mar 28 10:55   still logged in
app-user    ftp          app-host         Mon Mar 28 10:55 - 10:55  (00:00)
app-user    ftp          app-host         Mon Mar 28 10:55 - 10:55  (00:00)
app-user    ftp          app-host        Mon Mar 28 10:55 - 10:55  (00:00)
app-user    ftp          app-host         Mon Mar 28 10:55 - 10:55  (00:00)
app-user    ftp          app-host        Mon Mar 28 10:54 - 10:54  (00:00)
app-user    ftp          app-host       Mon Mar 28 10:54 - 10:54  (00:00)
app-user   ftp          app-host         Mon Mar 28 10:53 - 10:53  (00:00)
app-user   ftp          app-host         Mon Mar 28 10:53 - 10:53  (00:00)
app-user  ftp          app-host         Mon Mar 28 10:53 - 10:53  (00:00)
$

Here's a section of my username from last :-

root@host # last |grep wisdom
wisdom    pts/1        <my IP address>   Mon Mar 28 10:43   still logged in
 

Hi this will help you.
ch dir where you want execute the script.
then find user.
ex:
cd /usr/ucb/
user=`who am i`
curr_user=`echo $user|awk -F" " '{print $1}'`