1826161 Members
4493 Online
109691 Solutions
New Discussion

Finding oldest print job

 
SOLVED
Go to solution
Andy Torres
Trusted Contributor

Finding oldest print job

I appended a solved thread. It was suggested I start a new one. Original is here: http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xf01a543254bfd611abdb0090277a778c,00.html

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?
12 REPLIES 12
Patrick Wallek
Honored Contributor
Solution

Re: Finding oldest print job

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: Finding oldest print job

It's spooky how quick the community is. Thanks, guys. I'm going to adopt the "ls -t with a tail" suggestion. Points forthcoming...
Pete Randall
Outstanding Contributor

Re: Finding oldest print job

See, Andy?

I told you this would work better - you got Patrick's answer 26 minutes before you asked the question. Now that's service!!!

Is that going to do it for you?

Pete

Pete
Pete Randall
Outstanding Contributor

Re: Finding oldest print job

Hi (again) Andy,

Thanks for accepting the suggestion.

Can you attach your existing script. That might be a good starting point.

Pete

Pete
Andy Torres
Trusted Contributor

Re: Finding oldest print job

I just happened to notice this old thread and thought I'd post my solution.

We now do a find on the lp spool directory and cull the job number from the c-file name and basically rebuild the job number from the filenames, then xarg a cancel command to it. I managed to do it in one line. Here's the command. It cancels all jobs older than 14 days. We skip queue q0500. It's our VsiFax queue.

find /var/spool/lp/request/*/cA* -mtime +14 -exec ll {} \; | awk -F / '{print $6,$7}' | grep -v cannot | grep -v q0500 | sed 's/ cA/-/g' | cut -b 1-10 | xargs cancel
Geoff Wild
Honored Contributor

Re: Finding oldest print job

Interesting - here's how I do it:

lpstat -o |grep -v bytes|awk '$5ne"$M"{print $1}'|xargs cancel

That way I delete anything not in the current month - I run it on the 21st...

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.
Geoff Wild
Honored Contributor

Re: Finding oldest print job

Sorry - forgot to mention that:

M=`date +%b`


Or just in oneline:

lpstat -o |grep -v bytes|awk '$5ne"`date +%b`"{print $1}'|xargs cancel

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.
Andy Torres
Trusted Contributor

Re: Finding oldest print job

That's a good one for monthly maintenance. Our print server is pretty busy. We have to keep it tamed daily. I should mention that our solution is fallible. We cron it daily. If any queue accumulates a large number of jobs in the 24-hour period the find command will hit that goofy "list too long" error and the cleanup fails. We then have to manually cancel the jobs in the queue so the cron job can complete. But otherwise, this is working well for us. I have it email a summary of cancelled jobs so I can be alarmed when it fails.
Rick Garland
Honored Contributor

Re: Finding oldest print job

Found this to be useful for keeping tabs on print jobs.

A perl script that will check the requests and send email for any print jobs over X hrs old.

Make a cron to run this daily/weekly/monthly and get the results.

Attached perl script
Geoff Wild
Honored Contributor

Re: Finding oldest print job

Rick - 20 points for that sweet script!!!

Very nice...

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.
Andy Torres
Trusted Contributor

Re: Finding oldest print job

Yes, very helpful script. Thanks for the help again, guys. Well-deserved points assigned.
Andy Torres
Trusted Contributor

Re: Finding oldest print job

Just closing this thread so I don't have to keep checking back to assign future points.