[78eb866c] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
[6b7441a] | 3 | # This script was largely written by Jessica Hamrick (jhamrick), with |
---|
| 4 | # help from Kyle Brogle (broglek) |
---|
[78eb866c] | 5 | |
---|
| 6 | use strict; |
---|
| 7 | use warnings; |
---|
| 8 | |
---|
| 9 | use Net::CUPS; |
---|
| 10 | use Net::CUPS::Destination; |
---|
[7cdd65d] | 11 | use Getopt::Long; |
---|
[78eb866c] | 12 | |
---|
[7cdd65d] | 13 | my $usage = "Usage: gbq [-q QUEUE]\n"; |
---|
[78eb866c] | 14 | |
---|
[7cdd65d] | 15 | my $q = ""; |
---|
| 16 | GetOptions ('q|queue=s' => \$q); |
---|
[78eb866c] | 17 | |
---|
[6b7441a] | 18 | # if the -q option is not specified, then assume we're using the |
---|
| 19 | # default queue |
---|
[78eb866c] | 20 | if (!$q) { |
---|
[7cdd65d] | 21 | $q = "DEFAULT"; |
---|
[78eb866c] | 22 | } |
---|
| 23 | |
---|
[6b7441a] | 24 | # set configuration path, and complain if it doesn't exist |
---|
[78eb866c] | 25 | my $configpath = "$ENV{'HOME'}/.gutenbach/$q"; |
---|
[85a1ac1] | 26 | if (! -e $configpath) { |
---|
[0d02eca] | 27 | print "Queue '$q' does not exist! Did you forget to add it with 'gutenbach-client-config'?\n"; |
---|
[85a1ac1] | 28 | exit 1; |
---|
| 29 | } |
---|
| 30 | |
---|
[6b7441a] | 31 | # initialize the host and queue variables: host holds the address for |
---|
| 32 | # the machine on which the remote queue runs, and queue holds the name |
---|
| 33 | # of the printer |
---|
[78eb866c] | 34 | my ($host, $queue); |
---|
| 35 | |
---|
[6b7441a] | 36 | # load the configuration file (this will set $host and $queue) |
---|
[78eb866c] | 37 | if (-r $configpath) { |
---|
| 38 | local $/; |
---|
| 39 | my $fh; |
---|
| 40 | open $fh, $configpath; |
---|
| 41 | eval <$fh>; |
---|
| 42 | } |
---|
| 43 | |
---|
[6b7441a] | 44 | # initialize a new CUPS session |
---|
[78eb866c] | 45 | my $cups = Net::CUPS->new(); |
---|
[6b7441a] | 46 | # set the server to the one specified in the config file |
---|
[78eb866c] | 47 | $cups->setServer("$host"); |
---|
[6b7441a] | 48 | # set the printer name to the one specified in the config file |
---|
[78eb866c] | 49 | my $printer = $cups->getDestination("$queue"); |
---|
| 50 | |
---|
[6b7441a] | 51 | # if $printer is not defined, then throw an error |
---|
[9fdf4a1] | 52 | unless( $printer){ |
---|
| 53 | print "Cannot access queue $q...do you have network connectivity and permission to view the queue?\n"; |
---|
| 54 | exit 1; |
---|
| 55 | } |
---|
[6b7441a] | 56 | |
---|
| 57 | # print pretty headings and stuff |
---|
[78eb866c] | 58 | print "Queue listing for queue '$queue' on '$host'\n\n"; |
---|
[9dee329] | 59 | printf ("%-8s%-15s%s\n","Job","Owner","Title"); |
---|
| 60 | print "-"x70 . "\n"; |
---|
[6b7441a] | 61 | |
---|
| 62 | # get the list of jobs from the printer |
---|
[78eb866c] | 63 | my @jobs = $printer->getJobs(0, 0); |
---|
[6b7441a] | 64 | |
---|
| 65 | # initialize the job reference and job id variables |
---|
[78eb866c] | 66 | my ($job_ref, $jobid); |
---|
| 67 | |
---|
[6b7441a] | 68 | # for each job in the list of jobs: |
---|
[78eb866c] | 69 | foreach $jobid(@jobs) |
---|
| 70 | { |
---|
[6b7441a] | 71 | # get the reference to the job (so we can get various related |
---|
| 72 | # variables) |
---|
| 73 | $job_ref = $printer->getJob($jobid); |
---|
[78eb866c] | 74 | |
---|
[6b7441a] | 75 | # get the id of the job |
---|
| 76 | my $id = $job_ref->{'id'}; |
---|
| 77 | # get the user who printed the job |
---|
| 78 | my $user = $job_ref->{'user'}; |
---|
| 79 | # get the title of the job |
---|
| 80 | my $title = $job_ref->{'title'}; |
---|
| 81 | |
---|
| 82 | # print the job information to the screen |
---|
| 83 | printf ("%-8s%-15s%s\n","$id",substr("$user",0,15),substr("$title",0,47)); |
---|
[78eb866c] | 84 | } |
---|