Retour d’expérience :
lpstat -v me donne le nom de l’imprimante
lpstat -p « ${NomDeLImprimante1} » me donne l’état idle ou paused de l’imprimante
/usr/sbin/lpadmin -p « ${NomDeLImprimante1} » -E redémarre l’imprimante en pause
ce qui donne
/opt/usr_bin/RedemarreImprimanteEnPause.sh
#!/bin/bash
LOG="/tmp/RedemarreImprimanteEnPause.log"
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = " >> "$LOG";
date >> "$LOG";
NomDeLImprimante1="$(LANG=C lpstat -v|grep -v "device for PDF"|sed "s#device for \([^\:]*\)\:.*#\1#"|head -n 1)";
# LANG=C lpstat -v donne :
#device for Brother_Brother_DCP-J772DW: ipp://debdouze.local:631/printers/Brother_DCP_J772DW_USB
#device for PDF: cups-pdf:/
#on récupère NomDeLImprimante1="Brother_Brother_DCP-J772DW"
EnPause="False";
if [ "$(lpstat -p "${NomDeLImprimante1}"|tr "\n" ";"|sed 's#.*Paused;#Paused#')" == "Paused" ];then
EnPause="True";
fi;
if [ "${EnPause}" == "True" ];then
/usr/sbin/lpadmin -p "${NomDeLImprimante1}" -E;
echo "Redémarrage de L'imprimante ${NomDeLImprimante1}." >> "$LOG";
lpstat -p "${NomDeLImprimante1}" >> "$LOG";
else
echo "L'imprimante ${NomDeLImprimante1}, n'est pas en pause." >> "$LOG";
fi
et un cron :
*/1 * * * * bash /opt/usr_bin/RedemarreImprimanteEnPause.sh
Améliorations , erreurs possibles :
- une seule imprimante est gérée
- les évènements sont « pause » ou « non pause »
- la réponse de lpstat pourrait être différente
- le restart par lpadmin corrspond à cupsenable : meilleur choix?