[K12OSN] is there an app or logfile that...

Jeff Kinz jkinz at kinz.org
Mon Sep 27 21:02:54 UTC 2004


On Mon, Sep 27, 2004 at 12:53:53PM -0700, Huck wrote:
> shows how long a user was logged on? Date/Time/Machinename
> 
Yes- standard UNIX accounting tool, called "last"
field 1 - user name
field 2 - line they logged in on
field 3 - hostname or IP they logged in from (ws001, 002 etc.. )
followed by the date and time
followed by the length ofthe login in parens

Here is output of last command:
i#####################################################################
root     tty1                          Sat Sep 18 07:40   still logged in   
reboot   system boot  2.4.7-10enterpri Sat Sep 18 07:40         (9+09:17)   
jkinz    pts/0                         Wed Sep 15 14:40 - down  (2+15:27)   
reboot   system boot  2.4.7-10enterpri Wed Sep 15 14:38         (2+15:28)   
jkinz    pts/2        pern             Wed Sep 15 07:57 - crash  (06:41)    
jkinz    pts/2        red2             Sat Sep  4 16:10 - 16:23  (00:12)    
brownies pts/3                         Wed Sep  1 12:59 - 13:02  (00:02)    
brownies pts/1                         Wed Sep  1 12:59 - 13:02  (00:03)    
brownies pts/0                         Wed Sep  1 12:59 - 13:02  (00:03)    
root     tty2                          Wed Sep  1 12:58 - crash (14+01:40)  
brown    pts/5                         Wed Sep  1 12:37 - 13:02  (00:24)    
brown    pts/4                         Wed Sep  1 12:37 - 13:02  (00:24)    
brown    pts/3                         Wed Sep  1 12:37 - 12:59  (00:22)    
brown    pts/1                         Wed Sep  1 12:37 - 12:59  (00:21)    
brown    pts/0                         Wed Sep  1 12:34 - 12:59  (00:24)    
brownies pts/3                         Wed Sep  1 12:21 - 12:37  (00:16)    
jkinz    pts/2        pern             Wed Sep  1 12:17 - 14:44  (02:27)    
brownies pts/1                         Wed Sep  1 12:11 - 12:37  (00:26)    
brownies pts/0                         Wed Sep  1 12:04 - 12:34  (00:30)    

wtmp begins Wed Sep  1 12:04:05 2004


Here is quick hack script that looks for ws<n> hostnames and counts up usage
minutes:
#!/bin/bash
last | egrep "ws[0-9][0-9]*:0" | egrep "^ws" | awk '{print $10}' | sed -e 's/[(:)]/ /g' | awk '{cnt=cnt+1; tmin=(tmin + ($1 * 60 )); tmin=(tmin + $2 ); printf("Sessions: %d,  Average length %6.2f minutes, Total minutes served %d.\n", cnt,(tmin/cnt),tmin);}'

-- 
Linux/Open Source.  Now all your base belongs to you, for free.
============================================================
Idealism:  "Realism applied over a longer time period"

Jeff Kinz, Emergent Research, Hudson, MA.




More information about the K12OSN mailing list