In the middle of the night, I want to determine if anyone is sitting
at a Mac and if they are not and have not been recently, I want to
kill the open applications and shutdown the Mac (for energy
conservation). If there are open files (`lsof -u macuser` or
something similar), I'll probably stop and check again in an hour.
What I don't know however is how to determine if someone has used the
Mac recently (presumably with /bin/ps?)
Thanks a bunch.
Tom Stiller - 28 May 2008 01:36 GMT
In article
<69340953-4565-4436-a14a-b3bbba770074@p25g2000pri.googlegroups.com>,
> In the middle of the night, I want to determine if anyone is sitting
> at a Mac and if they are not and have not been recently, I want to
[quoted text clipped - 5 lines]
>
> Thanks a bunch.
See the "last" man page.

Signature
Tom Stiller
PGP fingerprint = 5108 DDB2 9761 EDE5 E7E3 7BDA 71ED 6496 99C0 C7CF
Wes Groleau - 28 May 2008 02:23 GMT
> In the middle of the night, I want to determine if anyone is sitting
> at a Mac and if they are not and have not been recently, I want to
[quoted text clipped - 3 lines]
> What I don't know however is how to determine if someone has used the
> Mac recently (presumably with /bin/ps?)
Here are four commands that should tell if someone is _currently_ on:
Indigo:~ userid2 $ last | grep logged
userid1 ttyp3 Tue May 27 20:10 still logged in
userid1 console Indigo.local Tue May 27 19:07 still logged in
userid2 ttyp2 Mon May 26 15:25 still logged in
userid1 ttyp1 Mon May 26 12:42 still logged in
userid1 ttyp0 Sat May 24 16:27 still logged in
Indigo:~ userid2 $ w
21:13 up 3 days, 12:48, 4 users, load averages: 0.22 0.26 0.28
USER TTY FROM LOGIN@ IDLE WHAT
userid1 p0 - Sat16 2days -
userid1 p1 - Mon12 31:48 -
userid2 p2 - Mon15 29:32 -
userid1 p3 - 20:10 - w
Indigo:~ userid2 $ who
userid1 ttyp0 May 24 16:27
userid1 ttyp1 May 26 12:42
userid2 ttyp2 May 26 15:25
userid1 ttyp3 May 27 20:10
Indigo:~ userid2 $ finger
Login Name TTY Idle Login Time Office Phone
userid2 Ze Admin p2 1d Mon 15:25
userid1 The Papa p0 2d Sat 16:27
userid1 The Papa p1 1d Mon 12:42
userid1 The Papa p3 Tue 20:10
Without the grep, 'last' can also be analyzed to identify how long ago
someone logged out. (Though I'm not really sure why that matters for
doing a shutdown.)
Unfortunately, all four are unreliable, at least in 10.3.9--NO ONE
was logged in on this machine this morning, yet it claims one has
been logged in since yesterday and another for three days.
There have been no crashes nor shutdowns to explain this.

Signature
Wes Groleau
Armchair Activism: http://www.breakthechain.org/armchair.html
Wes Groleau - 28 May 2008 02:25 GMT
> In the middle of the night, I want to determine if anyone is sitting
> at a Mac and if they are not and have not been recently, I want to
Your question here is not exactly the same as the question in the
subject line. The subject line question:
Indigo:~ wgroleau$ ps -auxww | grep Finder
userid1 784 0.0 1.6 100092 10280 ?? S 7:07PM 0:02.01
/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
-psn_0_10223617

Signature
Wes Groleau
There are some ideas so wrong that only a
very intelligent person could believe in them.
-- George Orwell
paris2venice@gmail.com - 28 May 2008 20:00 GMT
> paris2ven...@gmail.com wrote:
> > In the middle of the night, I want to determine if anyone is sitting
[quoted text clipped - 7 lines]
> /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
> -psn_0_10223617
I'm not sure why ps is behaving this way on my Mac. Have any idea?
$ ps -auxww
ps: No user named 'xww'
$ which ps
/bin/ps
$ ls -al /bin/ps
-rwsr-xr-x 1 root wheel 85536 Sep 23 2007 /bin/ps
$ md5 /bin/ps
MD5 (/bin/ps) = bce38c39ee7b501eaf00745b87ed0565
Wes Groleau - 29 May 2008 03:53 GMT
> I'm not sure why ps is behaving this way on my Mac. Have any idea?
>
> $ ps -auxww
> ps: No user named 'xww'
Thee are at least three different "flavors" of 'ps' in terms of command
line options. It took me a while to get used to -auxww after Solaris,
where (IIRC) the same thing was achieved with -efw
My guess is that you have a version of OS X later than 10.3.9
and Apple has decided to switch to one of the other two styles.

Signature
Wes Groleau
"But, Professor! I didn't plagiarize! I paid someone to
write the essay for me, and that person plagiarized!"
-- from http://rateyourstudents.blogspot.com
billy@MIX.COM - 28 May 2008 04:16 GMT
> In the middle of the night, I want to determine if anyone is sitting
> at a Mac and if they are not and have not been recently, I want to
[quoted text clipped - 3 lines]
> What I don't know however is how to determine if someone has used the
> Mac recently (presumably with /bin/ps?)
What you need to look at is the idle timer, but I think the only
way you'll be able to do that for a GUI session is by hacking its
location. On the other hand, if just sleeping the computer would
suffice (that drops the power consumption quite a bit), then that
is build into the os, and uses the same idle timer. You can set
the length of idle time until going to sleep in the Energy Saver
section of the System Preferences.
Sleeping is also kinder - work in progress may be affected by
killing apps for a forced shutdown, while sleep is generally
not fatal to anything.
You should test going to sleep with the actual apps running that
would be in the middle of the night, too - there are a few that
prevent it working...
Billy Y..
Bruce Esquibel - 28 May 2008 21:35 GMT
> In the middle of the night, I want to determine if anyone is sitting
> at a Mac and if they are not and have not been recently, I want to
[quoted text clipped - 3 lines]
> What I don't know however is how to determine if someone has used the
> Mac recently (presumably with /bin/ps?)
> Thanks a bunch.
Yeah, the worlds energy crisis can be traced down to these here macs.
Obviously you are up to something else but generally on any unix system, the
following commands will clue you in...
who
last | more
ps -fu username
That last one may not work on pre 10.5 systems, somewhere down the line they
changed ps from the bsd style to svr4 style so ymmv. Another ymmv is with
the last command, although I can't say it's traditionally broken, it relies
on another file called wtmpx (or wtmp) which isn't always updated properly.
You may see a "still logged in" from a connection six months ago but usually
the data at the top (first displayed) is fairly accurate.
-bruce
bje@ripco.com