fp:Belug 2008/printing service/ftp
From LinuxTag Public Wiki
(Difference between revisions)
Lutz.willek (Talk | contribs) |
Lutz.willek (Talk | contribs) |
||
Line 37: | Line 37: | ||
WORKDIR=$(find ${BASEDIR}/* -maxdepth 0 -type d) | WORKDIR=$(find ${BASEDIR}/* -maxdepth 0 -type d) | ||
+ | IFS=$'\n' | ||
### | ### | ||
Line 48: | Line 49: | ||
} | } | ||
- | + | CheckFile() { | |
- | + | ||
# Parameter: Dateiname | # Parameter: Dateiname | ||
# Rückgabe: 0=Datei drucken, 1=Datei umwandeln, 90=Datei noch unvollständig, sonst nicht drucken | # 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}') | |
- | export TYPE=$(file -b ${ | + | |
DoLog "TYPE=$TYPE" | DoLog "TYPE=$TYPE" | ||
case $TYPE in | case $TYPE in | ||
- | PDF | + | PDF|PostScript) return 0 ;; |
- | + | ||
ODF) return 1 ;; | ODF) return 1 ;; | ||
+ | ELF|ISO|ERROR:|Audio) return 99 ;; | ||
*) return 99 ;; | *) return 99 ;; | ||
esac | esac | ||
return 99 | return 99 | ||
} | } | ||
- | |||
PrintFile() { | PrintFile() { | ||
- | # Parameter: Dateiname | + | # Parameter: Dateiname |
# Rückgabe 0=ok !=0=Fehler | # Rückgabe 0=ok !=0=Fehler | ||
- | DoLog "PRINT $ | + | DoLog "PRINT ${PRINTER} ${*##*/}" |
- | lpr -U ftpuser -P${ | + | lpr -U ftpuser -P${PRINTER} ${*} && return 0 |
return 1 | return 1 | ||
} | } | ||
MoveFile() { | MoveFile() { | ||
- | # Parameter: Dateiname | + | # Parameter: Dateiname |
if [ ${STOREJOBS} == "true" ] ; | if [ ${STOREJOBS} == "true" ] ; | ||
then | then | ||
- | STORENAME=${ | + | STORENAME=${PRINTER}-${TIMESTAMP}-${1##*/} |
DoLog "STORE ${STORENAME}" | DoLog "STORE ${STORENAME}" | ||
- | mv ${ | + | mv ${*} ${STOREDIR}/${STORENAME} |
else | else | ||
- | mv ${ | + | mv ${*} /dev/null &>/dev/null |
+ | # aka: rm ${*} | ||
fi | fi | ||
return 0 | return 0 | ||
Line 98: | Line 97: | ||
Main() { | Main() { | ||
for PRINTERDIR in ${WORKDIR} ; do | for PRINTERDIR in ${WORKDIR} ; do | ||
- | PRINTER=${PRINTERDIR##*/} | + | export PRINTER=${PRINTERDIR##*/} |
- | + | find ${PRINTERDIR} -maxdepth 1 -type f |\ | |
+ | while read JOB; do | ||
export TIMESTAMP=$(date "+%y%m%d%H%M") | export TIMESTAMP=$(date "+%y%m%d%H%M") | ||
CheckFile ${JOB}; RETURN=$? | CheckFile ${JOB}; RETURN=$? | ||
case $RETURN in | case $RETURN in | ||
- | 90) | + | 90) DoLog "still in use: ${JOB}" ;; |
- | 0) PrintFile ${JOB} ${PRINTER} ;; | + | 99) DoLog "not printable: ${JOB}" |
- | 1) ConvertFile ${JOB} ${PRINTER} ;; | + | MoveFile ${JOB} ;; |
+ | 0) PrintFile ${JOB} | ||
+ | MoveFile ${JOB} ${PRINTER} ;; | ||
+ | 1) ConvertFile ${JOB} ${PRINTER} | ||
+ | MoveFile ${JOB} ${PRINTER} ;; | ||
esac | esac | ||
- | |||
done | done | ||
done | done | ||
Line 113: | Line 116: | ||
Main $* | Main $* | ||
- | |||
- | |||
</pre> | </pre> |
Latest revision as of 20:19, 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) 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 $*