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