fp:Belug 2008/printing service/ftp
From LinuxTag Public Wiki
Revision as of 20:19, 18 May 2008 by Lutz.willek (Talk | contribs)
Aufgrund der Anfragen wie Drucken über FTP geht: hier die erste Version des Skriptes, wie es zu Testzwecken zum Einsatz kommt. Verbesserungen sind natürlich willkommen.
#!/bin/sh #****************************************************************************************** #* * #* Druckt Dokumente aus dem FTP-Bereich, Einsatz als Cronjob oder ueber * #* Tools wie filewatch (http://filewatch.sourceforge.net/) * #* * #* Script-Name : ftp-drucker-ueberwachung.sh * #* Autor : Lutz Willek http://belug.de * #* Copyright : Lutz Willek <lutz.willek@belug.de> GPL v.3+ * #* Erstellt am : 18.05.2008 * #* * #* Geaendert: * #* Datum Par Ver. Bemerkung * #* ----------+---+-----+---------------------------------------------------------------- * #* 18.05.2008 LW 1.00 Grundversion * #* * #* * #****************************************************************************************** # debug set -x BASEDIR=/home/ftpuser/ftp/pub/printers TEMPDIR=/tmp STOREJOBS=true STOREDIR=/home/ftpuser/ftp/pub/stored_printing_jobs SYSLOG=true FILELOG=true LOGFILE=/tmp/logdatei.log ### WORKDIR=$(find ${BASEDIR}/* -maxdepth 0 -type d) IFS=$'\n' ### DoLog() { # Loggt alles was als Parameter uebergeben wurde [ ${SYSLOG} == "true" ] && logger $* [ ${FILELOG} == "true" ] || return 0 echo "$TIMESTAMP $*" >> ${LOGFILE} return 0 } CheckFile() { # Parameter: Dateiname # Rückgabe: 0=Datei drucken, 1=Datei umwandeln, 90=Datei noch unvollständig, sonst nicht drucken fuser "${*}" && return 90 # fuser gibt $?=0, wenn wenigstens ein zugriff gefunden wurde export TYPE=$(file -b "${*}" |awk '{print $1}') DoLog "TYPE=$TYPE" case $TYPE in PDF|PostScript) return 0 ;; ODF) return 1 ;; ELF|ISO|ERROR:|Audio) return 99 ;; *) return 99 ;; esac return 99 } PrintFile() { # Parameter: Dateiname # Rückgabe 0=ok !=0=Fehler DoLog "PRINT ${PRINTER} ${*##*/}" lpr -U ftpuser -P${PRINTER} ${*} && return 0 return 1 } MoveFile() { # Parameter: Dateiname if [ ${STOREJOBS} == "true" ] ; then STORENAME=${PRINTER}-${TIMESTAMP}-${1##*/} DoLog "STORE ${STORENAME}" mv ${*} ${STOREDIR}/${STORENAME} else mv ${*} /dev/null &>/dev/null # aka: rm ${*} fi return 0 } ConvertFile() { # Parameter: Dateiname Druckerwarteschlange # Rückgabe 0=ok !=0=Fehler DoLog "CONVERT $1" #todo: umwandeln, dann direkt drucken return 0 } Main() { for PRINTERDIR in ${WORKDIR} ; do export PRINTER=${PRINTERDIR##*/} find ${PRINTERDIR} -maxdepth 1 -type f |\ while read JOB; do export TIMESTAMP=$(date "+%y%m%d%H%M") CheckFile ${JOB}; RETURN=$? case $RETURN in 90) DoLog "still in use: ${JOB}" ;; 99) DoLog "not printable: ${JOB}" MoveFile ${JOB} ;; 0) PrintFile ${JOB} MoveFile ${JOB} ${PRINTER} ;; 1) ConvertFile ${JOB} ${PRINTER} MoveFile ${JOB} ${PRINTER} ;; esac done done } Main $*