Operating System - HP-UX
1826432 Members
4038 Online
109692 Solutions
New Discussion

Shell Script to kill print request

 
Simran_1
New Member

Shell Script to kill print request

Hi all, hope you guys can help me out here. I am looking to write a short shell script in hpux to kill all print requests which are older than 1 day.

find /var/spool/lp/request/$PRINTER -mtime +0

Need some advise. THanks in advance.
8 REPLIES 8
RobertK_1
Occasional Advisor

Re: Shell Script to kill print request

for i in `/var/spool/lp/request/$printer -mtime +1`
do
rm -rf $i
done


Regards,
Robert
Simran_1
New Member

Re: Shell Script to kill print request

Thanks! Appreciated
Simran_1
New Member

Re: Shell Script to kill print request

Is there any way to use the 'cancel' command to kill the print request by getting the print request ID?

Sorry n00b here..:)
skt_skt
Honored Contributor

Re: Shell Script to kill print request

all the print requests come to the request directory. So you dont need to go behind the request id if the intention to cancel the one day old jobs?
Simran_1
New Member

Re: Shell Script to kill print request

Santosh,
Thanks. Lets just say that i do not have root capability...is there any way to do this.

I would like to know if there is a way to 'get' the print request id and parse it in the script...allowing a cancel.

like:

cancel $PRTID

Appreciate the inputs so far.
Dennis Handly
Acclaimed Contributor

Re: Shell Script to kill print request

>I would like to know if there is a way to 'get' the print request id and parse it in the script, allowing a cancel.

PRINTER=XXX
for lp in $(find /var/spool/lp/request/$PRINTER -mtime +1 -name "cA*") ; do
# get base, strip off leading "cA", then strip off hostname
base=${lp##*/}
lp_id=${base#cA}
lp_id=${lp_id%$(hostname)}
echo cancel $PRINTER-$lp_id
done

Remove "echo" when happy.
Rita C Workman
Honored Contributor

Re: Shell Script to kill print request

Here's an old case statement we set up for helpdesk folks to handle some quick requests on HPUX....it's nothing fancy..

#!/usr/bin/sh
#
#
#
trap '' INT
function cont
{
print -n "Do You Wish to Continue Y/N : "
read answ
if [[ $answ = [Yy] ]]
then
return 0
else
return 1
fi
}
while true
do
clear
print -n "
* HELP DESK MENU *
$(uname -n)
HELLO: $(whoami)
===================================================
1. Run Restricted SAM to reset passwords.

2. Display printer status / print jobs.

3. Cancel a print job.

4. Cancel ALL print jobs for a printer.

5. EXIT this program and RETURN TO COMMAND LINE.
===================================================

Select an Option # from above: "

read answer
case "$answer" in
5*|Qq|bye|Ee ) print "Quitting! See You Later, $(whoami)" ; exit ;;
1) if cont
then
. /usr/sbin/sam
fi;;
2) if (( $? == 0 ))
then
print -n "Enter Printer Name: "
read prtr
lpstat $prtr
print -n "OK to clear screen [Hit Any Key]"
read h
fi;;
3) if (( $? == 0 ))
then
print -n "Enter Printer Name-job#: "
read prtr
cancel $prtr
fi;;
4) if (( $? == 0 ))
then
print -n "..Enter printer name :"
read prtr_name
print -n "You enter printer ${prtr_name}"
print -n " Is this correct Y/N "
read answ
if [[ "$answ" = [Yy] ]]
then
lpstat $prtr_name | grep $prtr_name | sort -k1 | cut -d " " -f1 > $prtr_name.out
for rem_prt in `cat $prtr_name.out`
do
cancel $rem_prt
done
else
echo "No Such Printer"
fi



fi;;
esac
done


Number 3 and 4 may assist you..
Rgrds,
Rita
skt_skt
Honored Contributor

Re: Shell Script to kill print request

i hope you are not trying cancel other's job too whihc are more than a day old. A use can cancel only his job