1

I'm trying to find a Linux equivalent of running who -m in Unix. In Unix, who -m gives the first user ID you used to log in, before starting any new shell sessions through su, etc.

The -m switch to who has a different effect in Linux, and I'm unable to find anything relevant to my needs in the man pages so far.

narwahl
  • 33
  • 7
  • I FOUND A WORKAROUND! `ls -l \`tty\` | awk '{print $3}'` returns the expected output consistently across Linux systems, while `who -m` works on some but not others. – narwahl Mar 03 '17 at 07:07
  • Ideally I would still like to know a `who` way. – narwahl Mar 03 '17 at 07:08

1 Answers1

0

Update: My answer (who am i) is correct, your terminal is either broken or not configured correctly to support the functionality.

Based on the comments, I've done some more research and I asked a friend to help. You don't say which terminal you are using but it's likely doing the same thing as gnome-terminal.

In respect of gnome-terminal* when the terminal is started, it does not update the utmp file. This appears to be a design decision. Later when who reads utmp to find out the relevant information it's not there so it just exits and prints nothing.

* I tries xterm, konsole and ssh to various distros.


You want who am i which prints the invoking user as opposed to whoami which tells you the username of the current effective user

If given two non-option arguments, 'who' prints only the entry for the user running it (determined from its standard input), preceded by the hostname. Traditionally, the two arguments given are 'am i', as in 'who am i'.

That is buried in info coreutils 'who invocation' So interestingly (on a linux coreutils based system) who xyzzy plugh works as well.

user9517
  • 114,104
  • 20
  • 206
  • 289
  • Logged in on my local GNOME console, `who mom likes` prints nothing. – Michael Hampton Mar 03 '17 at 06:37
  • Thanks! I see now that my Linux sample size should have been larger. I tried a couple more and found one that works in the way you explained: `who am i` and `who -m` both return the same output on that system actually. However, on the first ones I looked at, they return no output at all. `root@server:/root $ who am i` `root@server:/root $ who -m` `root@server:/root $ which who` `/usr/bin/who` – narwahl Mar 03 '17 at 06:42
  • The man page on the systems where it doesn't work shows, for option -m: `-m Output only information about the current terminal.` There is no info in the man page for `who am i` on those sytems. `info who` gives the expected info, but it doesn't behave that way when executed. – narwahl Mar 03 '17 at 06:47
  • The *other* man page (one is man 1p, the other is man 1), shows this for -m: `-m only hostname and user associated with stdin`. Either way, blank line haha. – narwahl Mar 03 '17 at 06:49
  • @MichaelHampton `who am i` and `who mom likes` work as expected on C6.8, C7.3 , F25 (knosole) and Ubuntu 16.04 – user9517 Mar 03 '17 at 07:11
  • I've looked at the utmp file and I believe you're correct. It is xterm on SLES 11 SP3 however. – narwahl Mar 03 '17 at 19:57
  • http://www.verycomputer.com/171_ec4226b67f099503_1.htm – user9517 Mar 03 '17 at 20:02
  • Haven't found a way to get the suggested parm to work on my box. That article is 21 years old... I'm guessing /usr/share/X11/etc/app-defaults/{XTerm, XTerm-Color} have changed since then. I did a good bit of playing with configs in /usr/share/X11/etc and /usr/lib/X11 and couldn't get XTerm to write to utmp. The `+ut` option is supposed to take care of that when passed directly to xterm... I can't find where to set that at login time. I'm ready to cut my losses though & use the workaround I commented on the OP. It would be a pain anyway to implement the xterm config change on 1000s of servers. – narwahl Mar 05 '17 at 00:37
  • I really appreciate your help on this one. It has definitely been informative. – narwahl Mar 05 '17 at 00:37