Printer Accounting File Parsing
Larry Wall
lwall at jpl-devvax.JPL.NASA.GOV
Sat Aug 11 10:02:38 AEST 1990
In article <24110 at adm.BRL.MIL> BKEHOE%widener at pucc.princeton.edu writes:
:
: Here's something that should be simple to solve..it can be in anything (C/
: awk/shell/whatever).
: I need to parse down the results of the printer accounting file into a total
: for each user for that 2-week or month-long period of time, and send mail to
: those users that've gone above 50 pages saying something like "Calm down".
: I've been futzing in awk but can't seem to pull it off -- and in C my string
: manipulation seems to be off (admittedly I haven't spent a *lot* of time
: hacking it out).
: ...
: It'd be nice if I could assess the # of pages they print off of each client
: too, but that may be overkill.
No problem.
---------- CUT HERE ----------
#!/usr/bin/perl
$THRESHOLD = 50;
while (<>) {
($pages, $wherewho) = split(' ');
($where, $who) = split(/:/, $wherewho);
$sum{$who} += $pages;
$client{$who} .= "$where " unless $clientsum{$wherewho};
$clientsum{$wherewho} += $pages;
}
foreach $who (keys %sum) {
next if $sum{$who} < $THRESHOLD;
@clients = sort split(' ', $client{$who});
$breakdown = '';
if (@clients >= 2) {
$breakdown = "Breakdown:\n\tMachine \tPages\n";
foreach $client (@clients) {
$breakdown .= sprintf("\t%-16s%5d\n",
$client, $clientsum{"$client:$who"});
}
}
open(MAIL,"|/bin/mail $who") || die "Can't run mail: $!\n";
print MAIL <<EOF;
Subject: printer usage
Dear $who:
You printed $sum{$who} pages in the last accounting period. Calm down.
$breakdown
Sincerely,
The Printer Accounting Daemon
EOF
close MAIL;
}
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
More information about the Comp.unix.questions
mailing list