#!/bin/bash
#
# verification des files d'attente
#
#for i in 113-03-bac8
for i in $(cat /root/liste_imp)
do
#t=$(lpstat -p $i)
#s=$(lpstat -p $i|grep printer)
r=$(lpstat -p $i|grep printer|awk '{print $3}')
#echo i: $i - r : $r - s : $s - t : $t
# si l'imprimante est desactivée
if test "$r" = "disabled"
then
#echo desactivee
# si le lock n a pas encore été posé (i.e. si le fichier n'existe pas)
if test ! -e /tmp/$i.lock_verif_imp
then
echo attention une file d attention n est pas prete : $i
touch /tmp/$i.lock_verif_imp
fi
fi
done
#
# verification des locks
#
for i in $(ls /tmp/*.lock_verif_imp 2> /dev/null);
do
#echo fichier : $i
l=$(basename $i|awk -F. '{print $1}')
#echo lock pour $l
r=$(lpstat -p $l|grep printer|awk '{print $3}')
#echo $i $l $r
# si l'imprimante n est pas desactivée
if test "$r" != "disabled"
then
echo $l : suppression du lock, tout est rentré dans l ordre
rm $i
fi
done |