Operating System - HP-UX
1837260 Members
2607 Online
110115 Solutions
New Discussion

scripting help for LP command

 
SOLVED
Go to solution
Peter A. Berger Jr.
Regular Advisor

scripting help for LP command

UNIX newbie needs scripting help for boring manual process. Each day I do the following:
lpstat -o
cancel AcctHold_1-#### (where #### is the print job having the largest kb size)
enable AcctHold_1 (and wait 30sec)
disable AcctHold_1

This lpstat usually has only 2 print jobs, a small and super-huge one. Is there a way to make a script do the same steps above, but have it (script) automatically figure out which print job is the largest and kill that one? The two print jobs differ greatly in size. Any help/suggestions would be -- awesome. Thanks -- UX Newbie
12 REPLIES 12
Ramkumar Devanathan
Honored Contributor
Solution

Re: scripting help for LP command

hi Thomas,

Would be helpful if you could throw the output of the lpstat -o command.

- ramd.
HPE Software Rocks!
Geoff Wild
Honored Contributor

Re: scripting help for LP command

First, if it is always on printer AcctHold_1, then just do a :

lpstat AcctHold_1

Next, is the the name of the large file being printed always the same?
Is the size of the large file always the same?
Does the large file always get submitted at the same time?

That would make it easier - else you'll have to do some comparing with AWK....

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.
Rodney Hills
Honored Contributor

Re: scripting help for LP command

If you use perl, you can scan the "request" folder for the printer for print jobs.

$prt="AcctHold_1";
chdir("/var/spool/lp/request/$prt");
open(INP,"/usr/bin/find . -name 'd*' -print |");
while() {
chomp;
if ($sz=-s $_ > $big) { $fil=$_ ; $big=$sz; }
}
system("/usr/bin/cancel ${prt}-".(0+substr($fil,4,4)));

HTH

-- Rod Hills
There be dragons...
Peter A. Berger Jr.
Regular Advisor

Re: scripting help for LP command

Here's the exact output from lpstat in JPG format...
Robin Wakefield
Honored Contributor

Re: scripting help for LP command

Hi,

lpstat -o | awk '/^AcctHold/{req=$1;getline;if ($(NF-1)>max){kreq=req;max=$(NF-1)}}END{system("cancel "kreq)}'

should do it.

rgds, Robin
Geoff Wild
Honored Contributor

Re: scripting help for LP command

Robin - excellent AWKing! that's a 10 in my book.



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.
Mark Ellzey
Valued Contributor

Re: scripting help for LP command

Hi,

How is this print job being created? Rather than canceling the print job after the fact, you may want to look at where it's being created and handle it there.

Regards,
Mark
Peter A. Berger Jr.
Regular Advisor

Re: scripting help for LP command

Robin -- script worked great! The only issue I have now is that it doesn't run for normal users (ie: non-root). Gives me an error message about me not being the owner of the print job. Is there a way to run this script as ROOT (SUID?) so that it bypasses this error message? Thanks again. :)
Steve Steel
Honored Contributor

Re: scripting help for LP command

Hi

This will always remove the largest job.
Printer = parameter


3 lines in total

printer=$1

cancel $printer"-"$(find /var/spool/lp/request/$printer -type f -name dA*|

xargs du -s|sort -n|tail -n 1|sed -e 's/^.*dA//' |cut -c1-4)


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Robin Wakefield
Honored Contributor

Re: scripting help for LP command

Hi Peter,

I would probably incorporate sudo into the script, i.e.

system("sudo cancel "kreq)

If you haven't already got this utility, I'd recommend its use - it can be downloaded from:

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/sudo-1.6.6

rgds, Robin
John Meissner
Esteemed Contributor

Re: scripting help for LP command

If you need to cancel the same print job every day why not stop the print job from printing in the first place?

All paths lead to destiny
Peter A. Berger Jr.
Regular Advisor

Re: scripting help for LP command

closed