show printjobs per printer

This script shows all printjobs classified by printer.
this is useful to see which jobs are stalled in misconfigured printers.

#!/bin/bash

lpstat -o > jobs.txt
echo “Total Jobs: $(wc -l jobs.txt)”
lpstat -a | awk ‘{ print $1 }’ | while read p;do
J=$(grep $p jobs.txt|wc -l)
if [ $J -gt 0 ];then
nj=$(grep $p jobs.txt | wc -l)
echo ” $p : ${nj} jobs ———————-”
lpstat -p $p | egrep -iv ‘reason’
fi
done