Operating System - Linux
1827721 Members
2609 Online
109968 Solutions
New Discussion

A script to check the print queues?

 
SOLVED
Go to solution
B. Jen
Contributor

A script to check the print queues?

I like to create a script to check all the print queues? If print jobs are stuck in the queue for more than 10 minutes, it should send an email alert to the administrator.

Any suggestions?

Thank you in advanced for answers.
3 REPLIES 3
Geoff Wild
Honored Contributor
Solution

Re: A script to check the print queues?

Here's the correct script - just update YOU\@YOURDOMAIN.COM with your email address:

#!/usr/bin/perl -w
# script to email print jobs older then 3 hours
# can be modified for different time
# just update variables: STALE_TIME, $subject and $mailID
# gwild

use strict;
use constant VARLPDIR => "/var/spool/lp/request";
use constant STALE_TIME => (3 * 3600);

## define the variables for use
my $dirname = VARLPDIR;
my $stale = STALE_TIME;
my $now = time();
my $file;
my $prt;
my $prtjob;
my $line;
my $count;
my $HOST = "`hostname`";
my $subject = "print jobs over 3 hrs old - $HOST";
my $mailID = "YOU\@YOURDOMAIN.COM";
my $amtime = "strftime('%m-%d-%Y')";

open(MAIL, "|/usr/bin/mailx -s \"$subject\" $mailID");
opendir(VARLP, "/var/spool/lp/request") || die "Can't open the directory\n";
my @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));
closedir(VARLP);
foreach $file (@filelist) {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime) = stat("$dirname/$file");
opendir(PRTLST, "$dirname/$file") || die "Can't open\n";
my @prts = grep (!/^\./, grep (!/^d/, grep (!/^t/, readdir(PRTLST))));
closedir(PRTLST);
foreach $prt (@prts) {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime) = stat("$dirname/$file/$prt");
if ($now > ($mtime + $stale)) {
open(PRTFILE,"$dirname/$file/$prt");
my $count = 0;
while () {
$count++ ;
last if ($count == 3);
}
select(MAIL);
$| = 1;
print MAIL substr($_,1) unless /^$/;
}
}
}
close(MAIL);


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rick Garland
Honored Contributor

Re: A script to check the print queues?

The basics is that you are checking the date/time stamp of the files in the /var/spool/lp/request directory.

This is where print jobs are spooled off to before they are sent to the printer.

The perl script posted by Geoff can be set in cron to check the print queue as ofter as you like

Geoff Wild
Honored Contributor

Re: A script to check the print queues?

Bernard,

I also noticed that you havn't assigned points to any of your questions...

Please read:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Points help others who search determine which is the best answer to a question...

How many points should I assign to replies?
Every response to your question is eligible to earn between 1-10 points. No need to worry about running out of points - when a truly awesome reply rolls in that deserves a 10, you will be able to assign it a 10! However, be careful to assign points based on the value that a reply truly provides. Use the following scale as a guideline:



o N/A: The answer was simply a point of clarification to my original question

o 1-3: The answer didn't really help answer my question, but thanks for your assistance!

o 4- 7: The answer helped with a portion of my question, but I still need some additional help!

o 8-10: The answer has solved my problem completely! Now I'm a happy camper!


Although assigning points is not mandatory, it is a key component of a strong, interactive community, and it is STRONGLY ENCOURAGED. Others have taken time to help you, so please take a moment to give them credit for their assistance!


Thanks...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.