#!/usr/bin/perl -w use strict; use Getopt::Long; use Time::Local; my %opts = (); GetOptions(\%opts, "fs=s", "data=s", "user=s"); my $lastdate = ""; my @data = (); print STDERR "fs = ", $opts{"fs"}, "\n"; print STDERR "user = ", $opts{"user"}, "\n"; print STDERR "data = ", $opts{"data"}, "\n"; sub usage { print STDERR "Usage: $0 --fs= --user= --data=[bi]\n"; exit(1); } my @path = split(/:/, $ENV{PATH}); unless (grep { $_ eq "/usr/local/bin" } @path) { push @path, "/usr/local/bin"; } $ENV{PATH} = join(":", @path); while(<>) { my ($date, $fs, $user, $bused, $bsoft, $bhard, $iused, $isoft, $ihard) = split(/\t/); if ( ($opts{"fs"} ? $fs eq $opts{"fs"} : 1) && ($opts{"user"} ? $user eq $opts{"user"} : 1) ) { if ($date ne $lastdate) { my $time; if ($date =~ /(\d{4})-(\d{2})-(\d{2})T(\d{1,2}):(\d{2}):(\d{2})/) { $time = timelocal($6, $5, $4, $3, $2-1, $1-1900); } else { die "unparsable date $date\n"; } my $ld; if ($opts{data} eq "b") { $ld = [ $bused, $bsoft, $bhard ]; } elsif ($opts{data} eq "i") { $ld = [ $iused, $isoft, $ihard ]; } else { usage(); } push(@data, [ $time, $ld ]); $lastdate = $date; } } } open (DATA, ">quotastat.data") or die "cannot open quotastat.data for output: $!"; for (my $i = 0; $i <= $#data; $i++) { my $time = ($data[$i])->[0]; my $data = ($data[$i])->[1]; print DATA $time; for my $j (@$data) { print DATA "\t", $j + 0; } print DATA "\n"; } close(DATA); open (CTL, ">quotacheck.ctl") or die "cannot open quotacheck.ctl for output: $!"; # generic settings print CTL "set term postscript color\n"; print CTL "set output 'quotastat.ps'\n"; print CTL "set data style lines\n"; print CTL "set grid\n"; # compute ticks my $firsttime = ($data[0])->[0]; my $lasttime = ($data[$#data])->[0]; if ($lasttime - $firsttime > 3 * 30 * 24 * 3600) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; $mday = 1; $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; my $comma = 0; my $time; for (;;) { $time = timelocal($sec,$min,$hour,$mday,$mon,$year); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if (++$mon >= 12) { $mon = 0; $year++; } if ($time > $lasttime) {last} } $lasttime = $time; print CTL ")\n"; } elsif ($lasttime - $firsttime > 30 * 24 * 3600) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $firsttime -= 86400 * $wday; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; my $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; my $comma = 0; for (;;) { ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if ($time > $lasttime) {last} $time += 7 * 24 * 3600; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); my $toff = $hour * 3600 + $min * 60 * $sec; if ($toff != 0) { if ($toff > 12*3600) { $toff = 24 * 3600 - $toff; } print "correcting time by $toff seconds "; printf "from %04d-%02d-%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec; $time -= $toff; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); printf "to %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec; } } $lasttime = $time; print CTL ")\n"; } else { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($firsttime); $sec = $min = $hour = 0; my $time = $firsttime = timelocal($sec,$min,$hour,$mday,$mon,$year); print CTL "set xtics rotate ("; my $comma = 0; for (;;) { ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); if ($comma) { print CTL ", "; } else { $comma = 1; } printf CTL qq|"%04d-%02d-%02d" %d|, $year+1900, $mon+1, $mday, $time; if ($time > $lasttime) {last} $time += 24 * 3600; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); my $toff = $hour * 3600 + $min * 60 * $sec; if ($toff != 0) { if ($toff > 12*3600) { $toff = 24 * 3600 - $toff; } print "correcting time by $toff seconds "; printf "from %04d-%02d-%02d %02d:%02d:%02d ", $year+1900, $mon+1, $mday, $hour, $min, $sec; $time -= $toff; ($sec,$min,$hour,$mday,$mon,$year) = localtime($time); printf "to %04d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec; } } $lasttime = $time; print CTL ")\n"; } # what to plot print CTL qq{plot "quotastat.data" using 1:2 title "used", "quotastat.data" using 1:3 title "soft", "quotastat.data" using 1:4 title "hard"\n}; close (CTL); my $rc = system("gnuplot", "quotacheck.ctl"); print "system returned $rc\n"; my $fs = $opts{fs}; $fs =~ s|/|_|g; system("gs -sDEVICE=ppmraw -r150 -dBATCH -sOutputFile=- -q - < quotastat.ps |" . "pnmscale 0.5 |" . "pnmflip -cw |" . "pnmcrop |" . "ppmquant 256 |" . "ppmtogif >/usr/local/www/wsr/intranet/quotas/$opts{user}$fs.gif");