Changeset 1723

Show
Ignore:
Timestamp:
09/15/04 14:47:08 (20 years ago)
Author:
jalet
Message:

waitprinter.sh rewritten from scratch to wait for printer status
stabilization. New version contributed by Christian Andreetta and
Paolo Nobili.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/waitprinter.sh

    r1706 r1723  
    1414# $Id$ 
    1515# 
    16 # Fix by Matt Hyclak & Jerome Alet 
    17  
    18 trap "KILLED=1" TERM 
     16# First version by Matt Hyclak & Jerome Alet 
     17# Rewritten from scratch, and contributed to PyKota, by Christian Andreetta 
     18# and Paolo Nobili 
    1919 
    2020# If ending phase, after the job has been fully transmitted to the printer 
    2121# we have to wait for the printer being in printing mode before checking 
    2222# if it is idle, otherwise we could have problems with slow printers. 
     23#-------------------------------------------------------------------------- 
    2324PATH=$PATH:/bin:/usr/bin:/usr/local/bin:/opt/bin 
    24 if [ x$PYKOTAACTION != "xDENY" ] && [ x$PYKOTAPHASE = "xAFTER" ] ; then 
    25   until snmpget -v1 -c public -Ov $1 HOST-RESOURCES-MIB::hrPrinterStatus.1 | grep -i printing >/dev/null; do 
    26     if [ "$KILLED" = 1 ]; then 
    27       break ; 
    28     fi  
    29     sleep 1 ; 
    30   done 
    31 fi 
    32  
    33 # In any case, wait until the printer is idle again. 
    34 until snmpget -v1 -c public -Ov $1 HOST-RESOURCES-MIB::hrPrinterStatus.1 | grep -i idle >/dev/null ; do  
    35   if [ "$KILLED" = 1 ]; then 
    36     break ; 
    37   fi  
    38   sleep 1 ; 
    39 done 
     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=1    #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$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 $? 
  • pykota/trunk/CREDITS

    r1716 r1723  
    130130  - Johannes Laemmermann - German translation 
    131131  - Paulo Silva - Eurotux - Improved ESC/P2 miniparser 
     132  - Christian Andreetta - SNMP waiting script 
     133  - Paolo Nobili - Universit�egli Studi di Padova - SNMP waiting script 
    132134 
    133135============================================================== 
  • pykota/trunk/NEWS

    r1717 r1723  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha12 : 
     25     
     26        - waitprinter.sh rewritten from scratch to wait 
     27          for printer status stabilization. 
     28         
    2429    - 1.20alpha11 :  
    2530     
  • pykota/trunk/pykota/version.py

    r1717 r1723  
    2222# 
    2323 
    24 __version__ = "1.20alpha11_unofficial" 
     24__version__ = "1.20alpha12_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""