Operating System - HP-UX
1822713 Members
3479 Online
109644 Solutions
New Discussion юеВ

deleting more than three days old print jobs

 
SOLVED
Go to solution
SAM_24
Frequent Advisor

deleting more than three days old print jobs

Hi,

How to delete more than three days old print job? Is thery any command? Or Do I have to write shell script? If it is shell script means how to compare date?

Thanks.
Never quit
12 REPLIES 12
S.K. Chan
Honored Contributor
Solution

Re: deleting more than three days old print jobs

When a file is printed it'll be spooled to /var/spool/lp/request/ before it is sent to the printer. 2 files will be created in this directory.
1) file that start with "c..." (for example c6544venus)
2) file that start with "d..." (for example c6544venus)
The first one is a control file and the second one is the data file itself. So if you want to remove a specific print job you would simple delete these 2 files. In your case if you want to delete say all print jobs older than 3 days for printer name "laser5" for example , you would ..
# cd /var/spool/lp/request/laser5
# find . -type f -atime +3 -exec rm -f {} \;
Just one question, why 3 days ? In my opinion there should not be any files left in the spooler directory which are older than 1 day unless there are tons of print jobs which some can take up to a days before it got printed.
SAM_24
Frequent Advisor

Re: deleting more than three days old print jobs

Hi Chan,

Thanks for your reply. Great.
In find command should I use -mtime option? If I use -atime it only lists d* files. mtime option lists both c* & d* files.

Thanks.
Never quit
Pete Randall
Outstanding Contributor

Re: deleting more than three days old print jobs

Hi Raj,

Sure, you can use -mtime. However, I would caution that you check the file name as well. There are (or may be) some status files like .remotesending or .sendingstatus that should probably be left alone. Add a -name check to your find to look specifically for c* and d* files and you should be fine.

Pete

Pete
Bart Paulusse
Respected Contributor

Re: deleting more than three days old print jobs

Hi Raj,

simply deleting the files from /var/spool/lp/request/ does not remove their entries from the /var/spool/lp/outputq file. This means your outputq file grows and grows. This is annoying when restarting the spooler. At startup lp wastes a lot of time looking for files that have already been deleted.
Depending on the amount of spool you delete this way, it may result in having to wait 20 minutes before you can print anything after bouncing the spooler...
I know some of my users wouldn't be happy with this.
I suggest you create a shell script that does a "cancel <$printername>-<$number>", where $printername is the name of the queue you're inspecting (with find) and $number is the numbers in the filename cA1234servername of your spool file. This way you remove the spool properly.

regards,

Bart
Pete Randall
Outstanding Contributor

Re: deleting more than three days old print jobs

That's probably a much better approach - thanks, Bart.

Pete

Pete
Andy Torres
Trusted Contributor

Re: deleting more than three days old print jobs

I'd like to take this to another level if I may.

I scripted a report that shows me the number of print jobs stacked up in our queues and how many of those are more than a day old. It's a nice report to get every morning to show general print server health.

What I'd really like to do is get a report of the one oldest job in each queue. If it's older than [whatever] days I can forward the list to our System Support department so they can investigate with our branches why their jobs aren't getting printed.

I've investigated using the find command on /var/spool/lp/[queue#] and lpstat options and it still eludes me.

Any ideas?
Pete Randall
Outstanding Contributor

Re: deleting more than three days old print jobs

Andy,

I've got one idea for you - start a new thread.

Refer back to this one by cutting and pasting the URL, if you wish, but adding on to this one, which already has the "magic answer" bunny is not going to be as fruitful.

Pete

Pete
Andy Torres
Trusted Contributor

Re: deleting more than three days old print jobs

Gotcha. Will do. Thanks.
Andy Torres
Trusted Contributor

Re: deleting more than three days old print jobs

Patrick Wallek
Honored Contributor

Re: deleting more than three days old print jobs

If you want to find the oldest control and data file pairs, something like this may work:

#!/usr/bin/sh

cd /var/spool/lp/request
PRINTERS=$(ls -1)

for P in PRINTERS
do
cd $P
OLDESTPAIR=$(ls -t c* d* | tail -2)
echo "Oldest files in $P are $OLDESTPAIR
cd ..
done

Andy Torres
Trusted Contributor

Re: deleting more than three days old print jobs

Thanks. Points awarded under new thread.
Patrick Wallek
Honored Contributor

Re: deleting more than three days old print jobs

If you want to find the oldest control and data file pairs, something like this may work:

#!/usr/bin/sh

cd /var/spool/lp/request
PRINTERS=$(ls -1)

for P in PRINTERS
do
cd $P
OLDESTPAIR=$(ls -t c* d* | tail -2)
echo "Oldest files in $P are $OLDESTPAIR
done