fp:Belug 2008/printing service/ftp
From LinuxTag Public Wiki
(Difference between revisions)
Lutz.willek (Talk | contribs) |
Lutz.willek (Talk | contribs) |
||
Line 103: | Line 103: | ||
CheckFile ${JOB}; RETURN=$? | CheckFile ${JOB}; RETURN=$? | ||
case $RETURN in | case $RETURN in | ||
- | 90) break ;; | + | 90) break ;; #file is still in use |
0) PrintFile ${JOB} ${PRINTER} ;; | 0) PrintFile ${JOB} ${PRINTER} ;; | ||
1) ConvertFile ${JOB} ${PRINTER} ;; | 1) ConvertFile ${JOB} ${PRINTER} ;; |
Revision as of 17:54, 18 May 2008
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) ### 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 # hint: fuser return $?=0 if at least one access has been found fuser ${1} || return 90 export TYPE=$(file -b ${1} |awk '{print $1}') DoLog "TYPE=$TYPE" case $TYPE in PDF) return 0 ;; PostScript) return 0 ;; ODF) return 1 ;; *) return 99 ;; esac return 99 } PrintFile() { # Parameter: Dateiname Drucker # Rückgabe 0=ok !=0=Fehler DoLog "PRINT $2 ${1##*/}" lpr -U ftpuser -P${2} ${1} && return 0 return 1 } MoveFile() { # Parameter: Dateiname, Printer if [ ${STOREJOBS} == "true" ] ; then STORENAME=${2}-${TIMESTAMP}-${1##*/} DoLog "STORE ${STORENAME}" mv ${1} ${STOREDIR}/${STORENAME} else mv ${1} /dev/null &>/dev/null 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 PRINTER=${PRINTERDIR##*/} for JOB in $(find ${PRINTERDIR} -maxdepth 1 -type f) ;do export TIMESTAMP=$(date "+%y%m%d%H%M") CheckFile ${JOB}; RETURN=$? case $RETURN in 90) break ;; #file is still in use 0) PrintFile ${JOB} ${PRINTER} ;; 1) ConvertFile ${JOB} ${PRINTER} ;; esac MoveFile ${JOB} ${PRINTER} done done } Main $*