Help with who am i . Not displaying real user

Hi

I'm trying to get the real username of any user running as root on my server. On one of my server running Sol 10, if I su to root and run who am i, it displays my username. which is what I want.

But when I run it on another server, this time on Sol 8, it displays root as the user. Is there anyway to get the actual user name?

Thank you in advance

Try

id -un

sorry that does not work..... illegal option.

/usr/xpg4/bin/id -un

Great! works...thanks!:b:

---------- Post updated at 09:47 AM ---------- Previous update was at 09:38 AM ----------

Spoke too soon, ignore my previous post.... didn't work when I su to root and ran it.

Anyway, I found a way round it with the command below... strange though!
w -h |cut -f1 -d" " |uniq`

Then please define better what output you expect depending on the various cases.

This is quite weak, especially if more than one user is logged in.

Very true.....
The required output is to display the real username, instead of displaying root as the user.
who am seems to work ok on my sol 10 servers, but on this sol 8, it's not. It keeps displaying that the real user is root.

Note I su to root on the server as opposed to login in as root. So it should really display my login name.

Try this (ksh or bash):

a=$(tty) ; w=$(w) ; a=$(echo $a | sed 's/\/dev\///') ; echo "$w" | grep -w "$a" | nawk '{print $1}'

Hmmmm..... it works on most of my servers, execpt this very one. I think it must be the way this particular server was built.

It doesn't output anything now on this particular server... When I broke the code down bit by bit, this is the output:

root@ # a=$(tty)
root@ # w=$(w)
root@ # a=$(echo $a | sed 's/\/dev\///')
root@ # echo "$w"
4:45pm up 188 day(s), 8:28, 1 user, load average: 0.00, 0.00, 0.01
User                             tty                login@      idle     JCPU      PCPU         what
<myusername>           pts/1       4:43pm        w
root@ #
root # echo "$w" |grep -w "$a"
root@ #

thanks for your help thogh, I guess I have to keep searching....

It would help if you post the tty command output (or $a value).