am I logged in locally?

Shane squindler at gmail.com
Fri Nov 10 01:13:25 CST 2006


does anyone have a nice way to test if a user is logged in locally /
physically to a machine? ...at the moment linux only but preferably
something that could be modified to also work on OS X too ..

At the moment I'm using this bit of code in tcsh (yeah tcsh sucks but
its what I'm stuck with for now)

set TTY = `tty | cut -d '/' -f3-`
set LOC = `w | grep $TTY | awk '{print $3}'`
if ( x$LOC == x'-' || x$LOC == x':0.0' ) then
    echo "you're local"
else
    echo "your remote"
endif

I just realised that this actually only tests that the user has a
local xsession on linux, which isn't 100% a good solution for what I
want though it is quite useful still ... be handy to find a simple
test for both local login & if they have an xsession ...

FYI - the x$LOC == x'-' test is for local logins on a Mac, seems to
work despite being a bit crude.

Cheers,
Shane.


More information about the linuxsa mailing list