Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need script to restart print que from cron

Status
Not open for further replies.

lblauen

Technical User
Aug 13, 2002
69
I have 3 or 4 print queues that like to die at night. I have to restart them every morning. I need a quick script to test lpstat | grep -v READY and list the queues that are down and issue the command enable DOCK264 or what ever the queue name is. I would like to have cron run the script every hour and reset print queues as needed. Can anyone help please.

Tnaks Lloyd.
 
I use this - feel free to amend :) ( you probably don't need the case statement)

Alex



function queue_status {
/usr/bin/enq -e "$@" | /usr/bin/awk '
$1 ~ /:$/ { print $0; next }
{ if (substr($0,1,7) != " ") print substr($0,1,24); }'
}; queue_status '-A' | grep @ | tr -s ' ' ' ' | cut -f1,3 -d" " | while read PQ STAT
do
if [ $STAT = "DOWN" ]
then
case $PQ in
HP5Si2N) PQ=HP5Si2NT
;;
HP5Si1N) PQ=HP5Si1NT
;;
fsadvic) PQ=fsadvice
;;
fsconsi) PQ=fsconsign
;;
fsmanif) PQ=fsmanifest
;;
fspacki) PQ=fspacking
;;
fspalle) PQ=fspallet
;;
fsmanms) PQ=fsmanmsp
;;
fmgiftw) PQ=fmgiftwar
;;
fminner) PQ=fminnerfe
;;
*)
;;
esac
echo $PQ >> /scripts/logs/pqlog
echo `date` >> /scripts/logs/pqlog
qadm -U $PQ
fi
done
 
hi lblauen ,
try with

integer x
x=0
enq -As | while read Line
do
x=$x+1
if [ $x -le 2 ] ; then # discards 1st 2 lines
continue
fi

Que=`echo $Line | awk '{print $1}'`
Dev=`echo $Line | awk '{print $2}'`
Sta=`echo $Line | awk '{print $3}'`

if [ $Sta != "READY" ] ; then
echo $Que $Dev $Sta $x
enq -P $Que -X
enq -P $Que -U
fi
done



I dont know if enq -X ( deletes all job ) is for you:
if not comment out it .


bye
 
hi lblauen ,

Try this :

enq -As | grep "DOWN" | cut -f 1 -d " " | while read ln
do
enable $ln
done

Best Regards,
vivek
 
Thanks for all the help. I got help from the unix scripting forum and here was the script which works great.

lpstat -W | grep -v READY | awk '$NF == "DOWN" { system("enable " $1) }'


Thanks again
 
OK, this is my last attempt to amend the shell coding using old methods.

1) replace [ "$var" = "$var" ] with [[ $var = $var ]]
this is a newer and more powerful method!

2) replace x=$x+1 with x+=1
this is faster and easier to read.

3) ksh93 allows the use of substrings
($var:eek:ffset:length) allows you to disregard calling awk within your shell script.

Well those are a few of my pet peeves for shell scripting. And I reserve the use of awk to one-liners like the solution above! as well as sed and most of my perl are one-liners.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top