On Tue, Aug 17, 2010 at 6:24 AM, LuKreme <[email protected]> wrote: > I have a logouthook setup on my machine, and I would like to write out to the > logs the total length of time of the GUI session in the logout hook, but I > can't seem to figure out a way to get it reliably. > > If the session is short, I can do > > $ ps Ac loginwindow | awk '{$print $1}' > > and this gives me a time string if the session is short enough and on the > right day that I then get to play with. However, if the session is long, I > will instead get something like "Fri07AM" which makes things difficult. > > I suppose I could write the login time in a loginhook and then grab that in > the logouthook, but it seems this should already be a property I can find > without resorting to that. > > The loginwindow event is logged, but not with the username. > > system.log:Aug 17 02:29:18 cerebus loginwindow[50661]: Login Window Started > Security Agent > > I guess I could probably look through the log for the PID and that will > probably be the right time, but how do I get the PID of the current … > > oh, well, yes. I could do that. > > grep "loginwindow\[`ps Ac | grep -i loginw | awk '{print $1}'`]" system.log > > but we have the problem of the system log having rolled (perhaps several > times) in the week or two a session has been active. > > Also, is there a hook like loginhook and logouthook that fires on a Fast User > Switching event? > > (if anyone cares, my logouthook is currently pretty lame, more a proof of > concept)
What about analyzing the output from "last | grep console" which gives, e.g., <user> console Fri Sep 11 09:26 - 11:02 (01:36) for a short session, <user> console Tue Aug 18 08:26 - 12:40 (1+04:14) for a session lasting 28 hours and 14 minutes. > #!/bin/bash > > /usr/bin/osascript <<EOF > set myName to do shell script "dscl . -read /Users/$1 RealName | tail -1" > say "Goodbye," & myName using "Alex" speaking rate 350 volume 1 > > EOF > > > -- > I CAN'T SEE DEAD PEOPLE Bart chalkboard Ep. BABF05 > > _______________________________________________ > MacOSX-talk mailing list > [email protected] > http://www.omnigroup.com/mailman/listinfo/macosx-talk > -- George N. White III <[email protected]> Head of St. Margarets Bay, Nova Scotia _______________________________________________ MacOSX-talk mailing list [email protected] http://www.omnigroup.com/mailman/listinfo/macosx-talk
