[xubuntu-users] Detecting login name after su
Kevin O'Gorman
kogorman at gmail.com
Fri Oct 4 20:42:32 UTC 2013
On Fri, Oct 4, 2013 at 1:03 PM, Peter Flynn <peter at silmaril.ie> wrote:
> On 10/04/2013 08:34 AM, Jan Henke wrote:
>> Hi,
>>
>> the command 'w' lists all currently logged in users together with the
>> source of the login. You can parse that output to look for you local
>> machine (IP address or reverse DNS name), then you have the user name.
>
> Hah! That's it, thanks...I had completely forgotten about it.
>
> $ ssh xyz at foo.bar.com
> xyz at foo.bar.com's password:
> Last login: Thu Oct 3 23:56:16 2013 from blort.bar.com
> $ sudo su -
> [sudo] password for xyz:
> # w -u | grep 'w -u$' | awk '{print $1}'
> xyz
> #
>
> gives the username you originally logged in as (here 'xyz').
>
> ///Peter
w is a new one on me. Interesting, and it has the info, but I can't
rely on getting it the way shown:
kevin at treat:~$ sudo su -
[sudo] password for kevin:
root at treat:~# w -u | grep 'w -u$'
root at treat:~# w -u
13:40:56 up 3 days, 6:48, 1 user, load average: 2.75, 2.40, 2.23
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
kevin tty7 Tue06 3days 3:35m 0.01s
/bin/sh /etc/xdg/xfce4/xinitrc -- /etc/X11/xinit/xs
root at treat:~#
--
Kevin O'Gorman
programmer, n. an organism that transmutes caffeine into software.
Please consider the environment before printing this email.
More information about the xubuntu-users
mailing list