Check Printers

Various Linux Stuff
Post Reply
thockman
Site Admin
Posts: 104
Joined: Thu Dec 15, 2005 5:51 pm
Location: Kansas City
Contact:

Check Printers

Post by thockman » Thu Mar 28, 2013 8:09 am

Here is a script that I use to monitor cups printers.

Code: Select all

#!/bin/bash
clear
emto="noreply@email.com"
emcc="another@email.com"

w_lpc=$(which lpc)
w_cupse=$(which cupsenable)
w_lpq=$(which lpq)
anyneed=$($w_lpc status | grep disabled)
if [ "$anyneed" ]; then
  for i in $($w_lpc status | grep ":" | grep -v PDF | grep -v test | grep -v grep | sed s/://g);
  do 
    pnr=$($w_lpq -P $i | grep "not ready")
    if [ "$pnr" ]; then
      $w_cupse $i
      logger "Restarted $i"
      pnr=$($w_lpq -P $i | grep "not ready")
      if [ "$pnr" ]; then
        echo -e "`hostname` has one or more offline printers. \n Printer did not restart! $pnr" | mail -s "Offline Printer Restart" $emto -c $emcc
        logger "Could not restart $i!  Email sent."
      fi
    fi
  done
fi

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest