Cancel Printing Problem

Hi guys,

Does any one know how to do script for cancel Print jobs. First it will ask for printer name or type and then show all print queus then remove jobs from the printer.
Thanks

What have you done so far?

Do you need to keep all prints of a particular month or you want to delete all print queues?

I need a script to do the cancel and I dont need to keep. What I have dont is show all Print qeues. But I need to get script select printer and then later show all the qeues

What I asked is do you want to 'delete all print jobs' or 'keep the recent week's jobs and delete previous all'?

Why i'm asking is because if you delete recent jobs also, all recent print requests qill be aborted

Ok cancel all the prevoius print qeues and just leave the current print qeues or else give sample with cancel all in one example and then keep the other one...

what have you done so far? Did you use lpstat?

Yes I have used lpstat..all I need is script to ask for printer and then show that qeues...
then it will allow me to cancel. That is what I need...
I can lpstat...but I need to put the rinter name'

Lets try to ask previous questions another way:

What can you not do in your script?

The idea of this forum is NOT to do your work for you... but Assist / Help you do your work

Yes What I cannot do is to get the printer name...or so..do I have to us read printer??? or set printer as a variable???

OK
1) you print on screen the info you want the user to enter using echo command:
e.g.

 echo "Please enter the printer : "

Then to get the input, Yes! you use read:

 read NPRINTER

Now NPRINTER is the name of the variable containing the value entered, you will need $ sign in front of its name to use the value, in the other words what was entered is $NPRINTER...
to check by yourself:

echo " NPRINTER = " $NPRINTER

Now your turn to do a bit of work...

Courage!

Do I need to use if else with this...to chech the printer?? and if no printer available then do other thing???
help needed

---------- Post updated at 10:26 AM ---------- Previous update was at 10:17 AM ----------

check this out dude...

#!/bin/bash
NLPrinter=Printer
echo " Please enter Printer Name"
read $NLPrinter
if [ $NLPrinter = "$#"  ]
        then
        lpstat -o
else
        lpstat
fi

Well if people need to cancel jobs, you do hope that the jobs exist in a queue...
I dont quite get your request...
Lets say you have a printer called lp1
Once the user will have entered lp1 and you read it, what will your script do with it?

Remember that a user has not enough privileges to cancel jobs he doesn't own (If that is the issue)

You are right in the sense a user could have had typos issues ( like me...), for that you would have to keep up to date a list of valid printer names to use and compare to the list or use something like:

 lpstat -t|grep lp1|wc -l

and see if greater than 0...

#!/bin/bash
NLPrinter=""
echo " Please enter Printer Name"
read NLPrinter
if [ $NLPrinter = "$#" ]  # This I dont understand since you read the value what
then                      # are you going to compare it with?
   lpstat -o
else
   lpstat
fi

Should it not be something more like this:

#!/bin/bash
NLPrinter=""
echo " Please enter Printer Name"
read NLPrinter
VALID=$(lpstat -t|grep $NLPrinter|wc -l)
if [ $VALID -gt 0 ] 
then
#if [ $NLPrinter = "$#" ]  # This I dont understand since you read the value what
#then                      # are you going to compare it with?
   lpstat -o $NLPrinter   # ?? 
else
   lpstat  $NLPrinter     # You know better than me the reason...
fi