HPE GreenLake Administration
- Community Home
 - >
 - Servers and Operating Systems
 - >
 - Operating Systems
 - >
 - Operating System - Linux
 - >
 - A script to check the print queues?
 
Operating System - Linux
        1840137
        Members
    
    
        2193
        Online
    
    
        110161
        Solutions
    
Forums
        Categories
Company
Local Language
                
                  
                  back
                
        
                
        
                
        
                
        
        
        
                
        
                
        
        
        
                
        
              
              Forums
Discussions
Forums
- Data Protection and Retention
 - Entry Storage Systems
 - Legacy
 - Midrange and Enterprise Storage
 - Storage Networking
 - HPE Nimble Storage
 
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
                
                  
                  back
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
                
            
            
                
            
                
            
                
            
                
            
            
                
            
                
            
            
                
            
                
              
            Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
 - Appliance Servers
 - Alpha Servers
 - BackOffice Products
 - Internet Products
 - HPE 9000 and HPE e3000 Servers
 - Networking
 - Netservers
 - Secure OS Software for Linux
 - Server Management (Insight Manager 7)
 - Windows Server 2003
 - Operating System - Tru64 Unix
 - ProLiant Deployment and Provisioning
 - Linux-Based Community / Regional
 - Microsoft System Center Integration
 
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
        Information
        Community
Resources
Community Language
        Language
        Forums
Blogs
	
		
			
            
                
            Go to solution
        
            
		
		
			
            	
	
		
        
		
	
	
		Topic Options
			
				
					
	
			
		
	- Subscribe to RSS Feed
 - Mark Topic as New
 - Mark Topic as Read
 - Float this Topic for Current User
 - Bookmark
 - Subscribe
 - Printer Friendly Page
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
09-08-2005 01:11 AM
09-08-2005 01:11 AM
			
				
					
					
						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.
	
			
				
		
			
			
			
			
			
			
		
		
		
	
	
	
Any suggestions?
Thank you in advanced for answers.
Solved! Go to Solution.
		3 REPLIES 3
	
	            
            
		
		
			
            
                - Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
09-08-2005 01:30 AM
09-08-2005 01:30 AM
Solution
			
				
					
					
						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 
					
				
			
			
				
		
		
	
	
	
#!/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.
			
			
				
			
			
			
			
			
			
		- Tags:
 - Perl
 
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
09-08-2005 01:42 AM
09-08-2005 01:42 AM
			
				
					
						
							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
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
		
		
	
	
	
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
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
09-08-2005 02:01 AM
09-08-2005 02:01 AM
			
				
					
						
							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
		
		
	
	
	
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.
			
			
				
			
			
			
			
			
			
		The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
		
	
	
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP