1829429 Members
2132 Online
109991 Solutions
New Discussion

while true loop

 
SOLVED
Go to solution
Norman_21
Honored Contributor

while true loop

hi guys,

I've written the following script to cancel a printer jobs queue but the script keeps prompting asking for an input again:

while true
do
echo "enter printer name ?\c"
read ANSW
cancel -e $ANSW
done

appreciate you advise and support..
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: while true loop

Yeah, that's what the while-true construct does.

To get out of that loop you'll have to do a CTRL-C

What exactly do you want the script to do? Do you want it to execute once? Do you want it to prompt the user before it executes again?

We need more info before we can effectively help you.
Balaji N
Honored Contributor

Re: while true loop

Hi,
The read statement is inside the while loop and hence as long as the while loop is true, it will prompt you for the input. Take the read statement out of the while loop.

BTW, what exactly are you trying. If you just need to cancel the jobs of a specific printer, just take away the loop and execute the rest of the commands.

Regards
Balajio
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Balaji N
Honored Contributor

Re: while true loop

Hi,
The read statement is inside the while loop and hence as long as the while loop is true, it will prompt you for the input. Take the read statement out of the while loop.

BTW, what exactly are you trying. If you just need to cancel the jobs of a specific printer, just take away the loop and execute the rest of the commands.

Regards
Balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Patrick Chim
Trusted Contributor
Solution

Re: while true loop

Hi,

You can modify your script like this,

while true
do
echo "enter printer name ?\c"
read ANSW
if [ x"$ANSW" = "x" ]
then
echo "program exit"
exit
fi
cancel -e $ANSW
done

If you just press "enter" at the question, the program will quit !!

Regards,
Patrick
S.K. Chan
Honored Contributor

Re: while true loop

If you want to cancel everything in all of the printer queue you can do this ..

for printername in $(lpstat|grep \^printer|awk '{print $4}')
do
cancel -e $printername
done

This command extract all the printername configured in your system.
$ lpstat|grep \^printer|awk '{print $4}'

Not sure if this is what you want.
Norman_21
Honored Contributor

Re: while true loop

Hi guys,

I realy appreciate your prompt reply. However, I was not sure if I removed the loop
the script will cancel the whole bunch of a specific printer jobs. I'll try and see what happens?
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003
Balaji N
Honored Contributor

Re: while true loop

Hi,
From the man pages of cancel.

-e Empty the spool queue of all requests for each printer.
Only users with appropriate privileges can use this
option.


So, if ur root and run cancel -e , it will cancel all requests.

HTH
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Norman_21
Honored Contributor

Re: while true loop

Closed...
"Attitudes are contagious, is yours worth catching"/ My first point was given by SEP on January 31, 2003