Operating System - HP-UX
1821416 Members
2741 Online
109633 Solutions
New Discussion юеВ

cleaning print jobs that was older than 3 days

 
SOLVED
Go to solution
tom quach_1
Super Advisor

cleaning print jobs that was older than 3 days

Hello,
i wouuld like to write a script that will clean out print jobs those are older that 3 day.
first i though the location
/var/spool/lp/request is the right place to work on, but the hp support advise that the cancel command was the only reliable way to remove print jobs from the queue while keeping the data file current.

lpstat -u |awk '{print$1}'|xargs -cancel
but then the print $1 will return the job # hp5000-1562 and J7009_stdlst. how do i get rid of this J7009_stdlst and add in the date so it only show me print jobs older than 3 day.

Thanks in advance.

Tom



hp5000-1562
J7009_stdlst
hp5000-1563
J7010_stdlst
hp5000-1564
J7008_stdlst
hp5000-1565
J7007_stdlst



hp5000-1532 batch priority 1 Jun 8 00:54
J7014_stdlst 6497 bytes
hp5000-1553 albany priority 0 Jun 8 01:16
ivanhoe1.txt 62 bytes
hp5000-1555 batch priority 1 Jun 8 02:12
J7011_stdlst 5073 bytes
hp5000-1556 batch priority 1 Jun 8 02:12
J7015_stdlst 4617 bytes
13 REPLIES 13
TwoProc
Honored Contributor
Solution

Re: cleaning print jobs that was older than 3 days

Of course HP has to tell you to remove them that's their job!

Anyway, here's a way to get it done which does use the script method to generate a file that has the cancel command in it. So, everyone is happy. Run this from cron once a day. Test this on a test system first right, OK? That's because this is really a script I use to see if any jobs are older than three days that I just changed on the fly for you to become a program to run cancel commands. It's not tested (I'm leaving that to you) but it should be fine - but you need to test it on a test server with junk stuff in the queue. Just change the "+2" value in the find command to "0" to make it delete stuff in queues from today on your test server - if you don't want to wait three days to test the code.

#!/bin/ksh
export mytmpfile=/var/tmp/old_print_jobs.$$
cd /var/spool/lp/request|| exit 22
for i in `find . -type f -name "cA*${HNAME}" -mtime +2`
do
printer=`echo $i | cut -f 2 -d"/"`
job=`echo $i | cut -f 3 -d"/"| sed -e "s/^cA//" -e "s/$HNAME//"`
echo /usr/bin/cancel -e ${printer}-${job}
done > $mytmpfile
typeset -i PRINT_JOB_CT
PRINT_JOB_CT=`cat ${mytmpfile}|wc -l`
if [[ $PRINT_JOB_CT -gt 0 ]]; then
. $mytmpfile
fi
rm $mytmpfile

We are the people our parents warned us about --Jimmy Buffett
Rick Garland
Honored Contributor

Re: cleaning print jobs that was older than 3 days

The request directory is where you want to be.
Attached perl script can do the job for you. Will list those jobs. Some minor mods and you can have it delete the jobs as well.

Rick Garland
Honored Contributor

Re: cleaning print jobs that was older than 3 days

Sorry, here is the script

Again, this is set to list the files. You can modify to delete as well.

tom quach_1
Super Advisor

Re: cleaning print jobs that was older than 3 days

Thanks-John and Rick,
i will test it.

Regards,
Tom
A. Clay Stephenson
Acclaimed Contributor

Re: cleaning print jobs that was older than 3 days

Actually, I agree with HP support; it's not nice to fool around with the request directory (or Mother Nature). The lpsubsystem is singly-threaded and you could cause problems by going about this in a non-standard way.

You can actually parse the output of lpstat -o using awk (or Perl) and then calculate the age of the job. You actually need two utilities so I have to do two attachments. 1) canceloldprjobs.sh 2) caljd.sh

There is a possibility that the job could appear to be newer than today. Consider lpstat returing Dec 31 and today is Jan 4. Because lpstat does not include the year, I first do the calculation and if the age is negative, I repeat using the previous year.

I've been using this script as a cron job for a long time.

Here's canceloldprjobs.sh

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: cleaning print jobs that was older than 3 days

Here's the other script that is used by canceloldprjobs.sh. Invoke as caljd.sh -u for full usage and examples.


I suggest that you install caljd.sh in /usr/local/bin.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: cleaning print jobs that was older than 3 days

One last point, I suggest that you uncomment the line in canceloldprjobs.sh that echos the job about to be cancelled and comment the line that calls cancel until you are satisfied with the results.
If it ain't broke, I can fix that.
tom quach_1
Super Advisor

Re: cleaning print jobs that was older than 3 days

Hi Clay
your scripts work beautifully. one question for you, if it is possible to use these scripts to cancel job of individual user.
ex: when i run the script manuall, it will prompt me for a user name and after insert the username it will clean out all spool files of that user.

Hi Rick,
when i ran your script, it sent back an email with a list of spoolfiles (cool)
but it did not delete the spoolfiles, I did modify (3 * 3600) to (1 * 1800) i think i did not do it right?
Eknath
Trusted Contributor

Re: cleaning print jobs that was older than 3 days

Hi Tom,

add grep in the line

lpstat -u |grep hp5000 |awk '{print$1}'|xargs -cancel

or alternatively you can use

lpstat -u |grep hp5000 |cut -c 8-12 |xargs -cancel

in your script

Cheers!!!
eknath
tom quach_1
Super Advisor

Re: cleaning print jobs that was older than 3 days

Thanks Eknath,
modified yours abit and that is what i want.

Thanks,
tom

#!/usr/bin/sh
echo 'Enter user name\n'
read USER
lpstat -u |grep $USER |awk '{print $1}'|xargs cancel
Rick Garland
Honored Contributor

Re: cleaning print jobs that was older than 3 days

You are right. The script is written to list thosr files that have the threshold - 3 days in your case.

By adding in the rm commands you can have it list those files, send an email, and then delete.

You know what is deleted in this manner.

tom quach_1
Super Advisor

Re: cleaning print jobs that was older than 3 days

Thank you all for your help.

Regards,

Tom
tom quach_1
Super Advisor

Re: cleaning print jobs that was older than 3 days

thanks,