home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10409 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.9 KB  |  45 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!convex!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: How to determine user login time in minutes?
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Aug26.201250.12162@news.eng.convex.com>
  8. Date: Wed, 26 Aug 1992 20:12:50 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <cosmo.714854795@cherry>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. Keywords: time, login, accounting
  14. X-Disclaimer: This message was written by a user at CONVEX Computer
  15.               Corp. The opinions expressed are those of the user and
  16.               not necessarily those of CONVEX.
  17. Lines: 26
  18.  
  19. From the keyboard of cosmo@cherry.ucsb.edu (Burtin;Boris;;;;COMS;Undergraduate;940630;911002;1000):
  20. :I'd like to keep track of how long I've used the system.  This should be done
  21. :in my .logout file.  I've played around with "last," but it won't give me the
  22. :time for the _current_ session (it says "still logged in").  
  23. :
  24. :Is there a utility that I'm missing?  Or does someone know of a script 
  25. :(preferably in Perl) that will figure out the login time?
  26.  
  27. If you have Cnews installed on your system, you can do this:
  28.  
  29.     #!/usr/bin/perl
  30.     $GETDATE = '/usr/local/lib/news/newsbin/getdate';
  31.     ($logtime) = `who am i` =~ /(\w{3}\s+\d+\s+\d+:\d+)/;
  32.     printf "%.2f minutes\n", (time - `$GETDATE "$logtime"`)/60;
  33.  
  34. If you don't have C news, you can do a lot of other things, 
  35. like you the getdate.pl produced from getdate.y by the perlian
  36. byacc, or you can look at ttys and utmp to figure it out.
  37. But this seems easiest to me.
  38.  
  39. --tom
  40. -- 
  41.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  42.  
  43. "The number of UNIX installations has grown to 10, with more expected."
  44.     - _The UNIX Programmer's Manual_, Second Edition, June, 1972.
  45.