Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Catching user switching and getting current active user from root on linux

Reply
Thread Tools

Catching user switching and getting current active user from root on linux

 
 
mpnordland
Guest
Posts: n/a
 
      11-30-2010
I have situation where I need to be able to get the current active
user, and catch user switching eg user1 locks screen, leaves computer,
user2 comes, and logs on.
basically, when there is any type of user switch my script needs to
know.
 
Reply With Quote
 
 
 
 
Tim Harig
Guest
Posts: n/a
 
      11-30-2010
On 2010-11-30, mpnordland <> wrote:
> I have situation where I need to be able to get the current active
> user, and catch user switching eg user1 locks screen, leaves computer,
> user2 comes, and logs on.
> basically, when there is any type of user switch my script needs to
> know.


Well you could use inotify to trigger on any changes to /var/log/wtmp.
When a change is detected, you could check of deltas in the output of "who
-a" to figure out what has changed since the last time wtmp triggered.
 
Reply With Quote
 
 
 
 
James Mills
Guest
Posts: n/a
 
      11-30-2010
On Wed, Dec 1, 2010 at 8:54 AM, Tim Harig <> wrote:
> Well you could use inotify to trigger on any changes to /var/log/wtmp.
> When a change is detected, you could check of deltas in the output of "who
> -a" to figure out what has changed since the last time wtmp triggered.


This is a good idea and you could also
make use of the following library:

http://pypi.python.org/pypi?:action=...&submit=search

cheers
James

--
-- James Mills
--
-- "Problems are solved by method"
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      12-01-2010
On 30/11/2010 22:47, mpnordland wrote:
> I have situation where I need to be able to get the current active
> user, and catch user switching eg user1 locks screen, leaves computer,
> user2 comes, and logs on.
> basically, when there is any type of user switch my script needs to
> know.


If it's Windows you're on, have a look at this:

http://timgolden.me.uk/python/win32_...on-events.html

TJG
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      12-01-2010
On 2010-11-30, mpnordland <> wrote:

> I have situation where I need to be able to get the current active
> user,


How do you define "current active user"?

> and catch user switching eg user1 locks screen, leaves computer,
> user2 comes, and logs on. basically, when there is any type of user
> switch my script needs to know.


What do you do when there are multiple users logged in?

--
Grant Edwards grant.b.edwards Yow! How's the wife?
at Is she at home enjoying
gmail.com capitalism?
 
Reply With Quote
 
Mark Wooding
Guest
Posts: n/a
 
      12-01-2010
Grant Edwards <> writes:

> On 2010-11-30, mpnordland <> wrote:
> > and catch user switching eg user1 locks screen, leaves computer,
> > user2 comes, and logs on. basically, when there is any type of user
> > switch my script needs to know.

>
> What do you do when there are multiple users logged in?


In case it's not clear: this situation doesn't just occur on `exotic'
systems like Unix servers. Even Windows systems can have several people
logged into the console (with one active, using `fast user switching')
and another one or two connected using terminal services.

-- [mdw]
 
Reply With Quote
 
mpnordland
Guest
Posts: n/a
 
      12-11-2010
sorry, I've been busy, it's on linux, and current active user is the
user currently using the computer. My program needs to switch log
files when a different user starts using the computer.
 
Reply With Quote
 
mpnordland
Guest
Posts: n/a
 
      12-11-2010
about the pyutmp, is the most recent entry at the top or bottom of the
file?

 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      12-11-2010
On 12/11/2010 01:43 PM, mpnordland wrote:
> it's on linux, and current active user is the user currently
> using the computer. My program needs to switch log files when
> a different user starts using the computer.


The problem is that multiple users can be logged on at the same
time. You might be able to come up with a solution that works
for a small set of use-cases, but I admin several Linux boxes
where multiple people can be logged-in at the same time. There
are also some multi-head arrangements (multiple
keyboards/mice/monitors and sometimes even sound-cards attached
to the same motherboard) and people can log into each "terminal"
(if you will) concurrently, all on the same box. So if I'm using
the computer, and a co-worker logs in, I'm still using it at the
same time you might catch the "new user logged in" event.

Watching wtmp (or possibly /var/log/auth) can capture the "hey,
somebody logged in" event, but that doesn't mean that other
previous users are done with their sessions.


-tkc



 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      12-11-2010
Mr. Chase, I really wouldn't even bother wasting my time on this one.
He asked an incomplete question to start with; so, the replies that
he received were insufficient to solve his problem. He still has not
provided enough information to know how to answer his question propery.
He doesn't understand a sacastic reply when he hears one, he doesn't
understand the concept of a multi-user operating system, and he doesn't
understand the concept of how usenet threads work. Until he demonstrates
some intelligence, I would say that he has flunked the Turing test.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an embedded Python runtime to use the current active virtualenv Brian Rossa Python 0 01-25-2012 06:36 PM
Process Switching vs. Fast/CEF Switching? asdf Cisco 7 05-29-2007 05:26 PM
non root users accessing application installed with root instance hector C Programming 5 12-05-2006 01:01 PM
SRT DIvision, Square root and reciprocal square root alghazo@siu.edu VHDL 0 05-27-2004 06:23 AM
Tertiary Conditional: what does this evaluate to ("docRoot == null ? this.root : doc root")? Rick Osborn Java 10 02-08-2004 02:25 AM



Advertisments