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 #
/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.
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.
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}'`