root / pykota / trunk / bin / waitprinter.sh @ 1832

Revision 1814, 3.5 kB (checked in by jalet, 20 years ago)

More complete PATH.
pkhint doesn't use absolute path to search for helper commands anymore.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /bin/sh
2#
3# PyKota - Print Quotas for CUPS and LPRng
4#
5# (c) 2003-2004 Jerome Alet <alet@librelogiciel.com>
6# You're welcome to redistribute this software under the
7# terms of the GNU General Public Licence version 2.0
8# or, at your option, any higher version.
9#
10# You can read the complete GNU GPL in the file COPYING
11# which should come along with this software, or visit
12# the Free Software Foundation's WEB site http://www.fsf.org
13#
14# $Id$
15#
16# First version by Matt Hyclak & Jerome Alet
17# Rewritten from scratch, and contributed to PyKota, by Christian Andreetta
18# and Paolo Nobili
19
20# If ending phase, after the job has been fully transmitted to the printer
21# we have to wait for the printer being in printing mode before checking
22# if it is idle, otherwise we could have problems with slow printers.
23#--------------------------------------------------------------------------
24PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/opt/bin:/sbin:/usr/sbin
25#--------------------------------------------------------------------------
26LOG_FILE=/var/log/pykota-waitprinter-snmpread.log
27LOG_DO_FLAG=""  #set different from null for file logging
28IDLE_WAIT_NUM=3 #number of snmp reads to consider the printer _really_ idle
29SNMP_DELAY=2    #seconds between snmp reads
30#--------------------------------------------------------------------------
31# END OF CONF
32#--------------------------------------------------------------------------
33function log_msg() {
34        if [ -n "${LOG_DO_FLAG}" ]; then
35                echo `date` "$*" >> ${LOG_FILE}
36        fi
37}
38#--------------------------------------------------------------------------
39function printer_status_get() {
40        local printer="$1"
41        PRINTER_STATUS=`snmpget -v1 -c public -Ov ${printer} HOST-RESOURCES-MIB::hrPrinterStatus.1`
42}
43#--------------------------------------------------------------------------
44function printing_wait() {
45        local printer="$1"
46        log_msg "CICLE: printing_wait"
47        while [ 1 ]; do
48                printer_status_get "${printer}"
49                log_msg "${PRINTER_STATUS}"
50                echo "${PRINTER_STATUS}" | grep -iE '(printing)|(idle)' >/dev/null && break
51                sleep ${SNMP_DELAY}
52        done
53}
54#--------------------------------------------------------------------------
55function idle_wait() {
56        local printer="$1" idle_num=0 idle_flag=0
57        log_msg "CICLE: idle_wait"
58        while [ ${idle_num} -lt ${IDLE_WAIT_NUM} ]; do
59                printer_status_get "${printer}"
60                log_msg "${PRINTER_STATUS}"
61                idle_flag=0
62                echo "${PRINTER_STATUS}" | grep -iE '(idle)' >/dev/null && idle_flag=1
63                if [ ${idle_flag} -gt 0 ]; then
64                        idle_num=$((idle_num+1))
65                else
66                        idle_num=0
67                fi
68                sleep ${SNMP_DELAY}
69        done
70}
71#--------------------------------------------------------------------------
72function main() {
73        local printer="$1"
74        log_msg "BEGIN"
75        ##log_msg "`ls -la /var/spool/{cups,samba}`"
76        log_msg "Pykota Phase: ${PYKOTAPHASE}"
77        if [ x$PYKOTASTATUS != "xCANCELLED" ] && [ x$PYKOTAACTION != "xDENY" ] && [ x$PYKOTAPHASE = "xAFTER" ] ; then
78                printing_wait "${printer}"
79        fi
80        idle_wait "${printer}" #in any case
81        ##log_msg "`ls -la /var/spool/{cups,samba}`"
82        log_msg "END"
83}
84#==========================================================================
85# MAIN
86#==========================================================================
87PRINTER_STATUS=""
88main "$1"
89exit $?
Note: See TracBrowser for help on using the browser.