print statistics about users' connect time

ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}'
'ac' is included in the package 'acct', which is described as "The GNU Accounting utilities for process and login accounting". Other interesting flags are: * print statistics for a specified user ac -d username * print statistics for all the users ac -p With my command, the output is also printed in a sexagesimal, more readable, style.
Sample Output
Jun  2	total       46.46 = 46h 27m 36s 
Jun  3	total       59.86 = 59h 51m 35s 
Jun  4	total       81.64 = 81h 38m 24s 
Jun  5	total       73.41 = 73h 24m 35s 
Jun  6	total       19.80 = 19h 48m 0s 
Jun  7	total       43.26 = 43h 15m 35s 
Jun  8	total       54.47 = 54h 28m 11s 
Jun  9	total       76.59 = 76h 35m 24s 
Jun 10	total       92.50 = 92h 30m 0s 
Jun 11	total       46.75 = 46h 45m 0s 
Jun 12	total       30.66 = 30h 39m 36s 
Jun 13	total       40.65 = 40h 38m 59s 
Jun 14	total       60.08 = 60h 4m 47s 
Jun 15	total       75.36 = 75h 21m 35s 
Jun 16	total       87.57 = 87h 34m 11s 
Jun 17	total       83.92 = 83h 55m 12s 
Jun 18	total       93.14 = 93h 8m 24s 
Jun 19	total      105.85 = 105h 50m 59s 
Jun 20	total       51.03 = 51h 1m 48s 
Jun 21	total       36.27 = 36h 16m 12s 
Jun 22	total       76.69 = 76h 41m 23s 
Jun 23	total       52.55 = 52h 32m 59s 
Today	total       29.55 = 29h 33m 0s 

-1
By: karpoke
2010-06-24 08:08:41

These Might Interest You

  • In this example, file contains five columns where first column is text. Variance is calculated for columns 2 - 5 by using perl module Statistics::Descriptive. There are many more statistical functions available in the module. Show Sample Output


    1
    perl -MStatistics::Descriptive -alne 'my $stat = Statistics::Descriptive::Full->new; $stat->add_data(@F[1..4]); print $stat->variance' filename
    alperyilmaz · 2010-04-02 21:16:12 0
  • GoAccess is an open source real-time Apache web log analyzer and interactive viewer that runs in a terminal in *nix systems. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. http://goaccess.prosoftcorp.com/ Show Sample Output


    0
    sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -s -b
    allinurl · 2010-12-13 17:37:33 0
  • Works on CentOS ad OpenBSD too, display time of accounts connection on a system, -p option print individual user's statistics. Show Sample Output


    2
    ac -p
    servermanaged · 2009-04-29 16:24:07 0
  • We can get useful statistics from tcpdump with this simple command. Thanks "Babak Farrokhi" to teaching me this ;)


    1
    tcpdump -nr capture.file | awk '{print }' | grep -oE '[0-9]{1,}.[0-9]{1,}.[0-9]{1,}.[0-9]{1,}' | sort | uniq -c | sort -n
    shahabv · 2011-06-16 19:27:11 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: