Cartridge usage monitoring in CUPS
Tags: Linux, Perl, Computing, Sys admin.
This is a quick'n'dirty Perl script I wrote to monitor the usage of print cartridges in my home network. It parses CUPS' /var/log/page_log log and a cartridge log provided by the user and counts how much pages were printed per cartridge. Optionally you can select only an arbitrary printer or user. An example will make it clearer:
[~]$ cartridge_usage.pl -PHP -u pepper -c cart_log Num Cartridge 66 Other 43 HP original 280 MaxPrint (1) 97 MaxPrint (2) Total: 486 pages.
This output tells us that 486 pages were printed by printer HP by user pepper, of which, 280 were printed using cartridge 'MaxPrint (1)', for example. In order to have the script working, it's necessary that a 'cart_log' (defaults to /var/log/cups/cart_log) exists. Its contents, for this example were:
[~]$ cat cart_log
01/Jan/2003:12:00:00 - Other
24/Mar/2004:13:00:00 - HP original
16/Apr/2004:14:34:00 - MaxPrint (1)
26/Apr/2004:18:00:00 - MaxPrint (2)
The script parses this log cartridge log file and based on the data provided by it and the cups pages_log, it generates the output shown above. Its syntax is really simple: installation_date - name, one per line. The installation date must be provided in the standard DD/mmm/YYYY:HH:MM:SS format, as shown. It is important that the date of install of the first cartridge is earlier than any printings cited on the cups pages_log. If you do not remember which cartridge you were using, just insert an 'Other' cartridge, as in the example, with a date safely earlier than the first printing shown in head /var/log/cups/pages_log.
Download
Link to download: cartridge_usage.pl.
All you need to run the script is a working Perl interpreter with the standard Perl libraries installed. For it to be of any use to you though, it would be interesting having cups installed, or at least having access to the cups page_log you want to analyse.
Command line parameters
The supported command line parameters are:
- -P printer: chooses the printer (defaults to any)
- -u user: chooses the user (defaults to any)
- -c clog: chooses the cartridge log (defaults to /var/log/cups/cart_log)
- -p cupslog: chooses the cups page log (defaults to /var/log/cups/page_log)
Creation date: 13/05/2004.