/[sysadmin-cookbook]/recepies/acct/lastcomm-duration.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /recepies/acct/lastcomm-duration.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations)
Sat May 2 14:46:34 2009 UTC (14 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 744 byte(s)
lastcomm-duration.pl 4

will return all commands longer than 4s

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use YAML;
7
8 my $too_long = shift @ARGV || 0.5; # s
9 my $stats;
10
11 open(my $lastcomm, '-|', 'lastcomm');
12 while(<$lastcomm>) {
13 chomp;
14 if ( m{^(\S+).+?(\S+)\s+(\S+)\s+(\d+\.\d+) secs} ) {
15 my ( $command, $user, $tty, $duration ) = ( $1, $2, $3, $4 );
16 $stats->{command}->{$command} += $duration;
17 $stats->{user}->{$user} += $duration;
18 $stats->{tty}->{$tty} += $duration;
19 print "$_\n" if $duration > $too_long;
20 } else {
21 warn "# $_";
22 }
23 }
24
25 foreach my $stat ( keys %$stats ) {
26 print "\n$stat:\n";
27 my $counter = $stats->{$stat};
28 foreach my $name ( sort { $counter->{$b} <=> $counter->{$a} } keys %$counter ) {
29 my $d = $counter->{$name};
30 printf "%8.2f %s\n", $d, $name if $d > $too_long;
31 }
32 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26