home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / lp-remote / remotelp / remote < prev   
Text File  |  1989-07-08  |  3KB  |  144 lines

  1. # NAME        /usr/spool/lp/model/remote
  2. # DATE        Thu Jul 14 13:31:26 BST 1988
  3. # AUTHOR    Paul Blackburn, DRSBC, ICL, Bracknell
  4. # PURPOSE    This is a 'remote' spooler script for any printer.
  5. #        This works by sending a 'uux' print request to a neighboring
  6. #        machine (NEXT).
  7. #
  8. #        This is a 'data-driven' script...
  9. #        /usr/spool/lp/db is used to get data for a particular printer.
  10. #
  11. #        (local) Options:
  12. #
  13. #            -os    = small print (portrait)
  14. #            -ol    = small print (landscape)
  15.  
  16. LOG=/usr/spool/lp/log
  17. DB=/usr/spool/lp/db
  18. MODEL=`basename $0`
  19. TEMP=/usr/tmp/${MODEL}.$$
  20.  
  21. if [ ! -f ${DB} ]
  22. then
  23.     echo "${MODEL}: unable to open ${DB}" >>$LOG
  24.     echo "${MODEL}: aborted" >>$LOG
  25.     exit 1
  26. fi
  27.  
  28. grep "^${MODEL}:" ${DB} >${TEMP}
  29.  
  30. DATA=`cat ${TEMP}`
  31.  
  32. if [ -z "${DATA}" ]
  33. then
  34.     echo "${MODEL}: unable to get data from ${DB}" >>$LOG
  35.     echo "${MODEL}: aborted" >>$LOG
  36.     rm -f ${TEMP}
  37.     exit 1
  38. fi
  39.  
  40. NEXT=`cut -f2 -d":" <${TEMP}`
  41. DESC=`cut -f3 -d":" <${TEMP}`
  42. RMODEL=`cut -f4 -d":" <${TEMP}`
  43. if [ -z "${RMODEL}" ]
  44. then
  45.     RMODEL=${MODEL}
  46. fi
  47. SMALL=`cut -f5 -d":" <${TEMP}`
  48. LAND=`cut -f6 -d":" <${TEMP}`
  49. rm -f ${TEMP}
  50.  
  51. echo "${MODEL}: DESC=${DESC}, NEXT=${NEXT}" >>$LOG
  52.  
  53. if [ -z "${NEXT}" ]
  54. then
  55.     echo "${MODEL}: unable to determine next machine" >>$LOG
  56.     echo "${MODEL}: aborted" >>$LOG
  57.     exit 1
  58. fi
  59.  
  60. TITLE=
  61. OPTIONS=
  62. COPIES=
  63.  
  64. if [ -n "$3" ]
  65. then
  66.     TITLE="-t\"$3\""
  67. else
  68.     user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
  69.     if [ -z "$user" ]
  70.     then
  71.         user=$2
  72.     fi
  73.     TITLE="-t\"${user}\""
  74. fi
  75.  
  76. if [ -n "$4" ]
  77. then
  78.     COPIES=-n$4
  79. fi
  80. param5=$5
  81.  
  82. shift;shift;shift;shift;shift
  83. files="$*"
  84.  
  85. # Split out local options from options for remote lp...
  86.  
  87. LOCALOPT=""
  88. for i in ${param5}
  89. do
  90.     echo "${MODEL}: option=${i}" >>${LOG}
  91.     case "${i}" in
  92.         s|l ) # local options
  93.             LOCALOPT="${LOCALOPT} ${i}"
  94.             ;;
  95.         * ) # other options simply passed to remote lp
  96.             OPTIONS="${OPTIONS} -o${i}"
  97.             ;;
  98.     esac
  99. done
  100.  
  101. OPTIONS="${OPTIONS} -oh"
  102. if [ -z "${LOCALOPT}" ]
  103. then
  104.     cat ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
  105. else
  106.     LOCALOPT=`echo ${LOCALOPT}`
  107.     for i in "${LOCALOPT}"
  108.     do
  109.         echo "${MODEL}: local option=${i}" >>${LOG}
  110.         case "${i}" in
  111.             s ) # small print (portrait)
  112.                 if [ -z "${SMALL}" ]
  113.                 then
  114.                     echo "${MODEL}: no small cmd\c" >>${LOG}
  115.                     echo " found in ${DB}" >>${LOG}
  116.                 else
  117. #                    echo "${MODEL}: small cmd:" >>${LOG}
  118. #                    echo "${SMALL}" | od -cx >>$LOG
  119.                     echo "${SMALL}"
  120.                 fi
  121.                 ;;
  122.             l ) # small print (landscape)
  123.                 if [ -z "${LAND}" ]
  124.                 then
  125.                     echo "${MODEL}: no land cmd\c" >>${LOG}
  126.                     echo " found in ${DB}" >>${LOG}
  127.                 else
  128. #                    echo "${MODEL}: land cmd:" >>${LOG}
  129. #                    echo "${LAND}" | od -cx >>$LOG
  130.                     echo "${LAND}"
  131.                 fi
  132.                 ;;
  133.             * ) # unknown!
  134.                 echo "${MODEL}: unknown local option" >>${LOG}
  135.                 ;;
  136.         esac
  137.     done|cat - ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
  138. fi
  139.  
  140. echo "${MODEL}: COPIES=${COPIES}, OPTIONS=${OPTIONS}, TITLE=${TITLE}" >> ${LOG}
  141. echo "${MODEL}: warning - ignoring title" >> ${LOG}
  142. echo "${MODEL}: completed on `date` for ${NEXT}" >> ${LOG}
  143. exit 0
  144.