How to auto-restart Cups printer queues

May 1, 2018
cups linux

This happens so many times - a printer goes offline and soon after CUPS disables the print queue requiring a manual cupsenable command.

Here is a short script I use to test for any disabled queues, and to then restart them one by one -

#!/bin/sh
# restart.sh
#
# Check if a printer queue is disabled and reenable it.
DISABLED=`lpstat -t | grep disabled | awk '{ print $2; }'`

for PRINTER in $DISABLED
do
    logger "Printer $PRINTER is stopped"
    /usr/sbin/cupsenable $PRINTER && logger "Printer $PRINTER has been enabled."
done

I usually setup a cronjob to schedule this every 15min -

0,15,30,45 * * * * /usr/local/bin/restart.sh

Extract the size of a file from a bash script

May 26, 2018
linux stat bash

Sorting a list in lexographic order using bash

May 26, 2018
bash linux sort

Setting the timezone on AWS Linux AMI from command line

May 7, 2018
aws linux timezone