-
Notifications
You must be signed in to change notification settings - Fork 0
/
cups_file.sh
63 lines (50 loc) · 1.51 KB
/
cups_file.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/ksh
# script for CUPS to print to files in a particular directory
# I got this somewhere, but can't recall where now.
# test for 5 or 6 params
FILE=${6:-"-"}
LOG=/tmp/receiptprint.log
export LOG
JOBID=$1
USER=$2
TITLE=$3
COPIES=$4
OPTIONS=$5
PID=$$
cat >> ${LOG} << EOF
${FILE}:
JOBID: ${JOBID}
USER: ${USER}
TITLE: ${TITLE}
COPIES: ${COPIES}
OPTIONS: ${OPTIONS}
EOF
# if there are no arguments: print "I'm here" message for cupsd's probing
if [ $# -eq 0 ] ; then
echo "direct receiptprint \"Unknown\" \"Print any job to file specified in device-URI\""
exit 0
fi
if [ $# -ne 5 -a $# -ne 6 ] ; then
cat << EOF
Usage: receiptprint job-id user title copies options [file]
examples for device-URI: 'receiptprint:/path/to/targetfile'
(this writes the printfile to disk at specified path)
Install a printqueue with 'lpadmin -p <receipt-printer-name> -v receiptprint:/<path/to/targetfile> -E [-P /path/to/PPD]
EOF
exit 1
fi
# sanitize $TITLE -- remove any spaces, colons and slashes or
# backslashes from filename
TITLE=`echo ${TITLE} | tr [:blank:] _ | tr : _ | tr / _ | tr "\134" _`
TARGETFILE=${DEVICE_URI#receiptprint:}
# For adding extra info into filename
#TARGETFILE=${DEVICE_URI#receiptprint:}-${TITLE}-${JOBID}-${USER}
# check "accepting" status first
GREPSTRING="not accepting"
if lpstat -a ${TARGETFILE} | grep "${GREPSTRING}" &> /dev/null ; then
echo "ERROR: printer ${TARGETFILE} not acceptings jobs..."
exit 1
fi
cat ${FILE} > ${TARGETFILE}
echo "INFO: printed receipt..." >&2
exit 0