มีปัญหาเรื่อง cups พิมพ์ผ่านเครือข่ายไม่ได้ เป็นอยู่เครื่องเดียว ไม่ทราบว่าเป็นเพราะอะไร
แก้ชั่วคราวด้วยการสร้างซอคเก็ตสำหรับรับงานพิมพ์ผ่านเครือข่าย (เผื่อเอาไว้เวลาอัปเกรดรุ่นบนเดเบียนแล้ว cups ชอบตายด้วย)
เอาความรู้จาก debian: ปรับปรุง HylaFax Client โดยใช้ perl สร้างเครื่องพิมพ์เทียมขึ้นมา โดย
ที่เครื่องปรินต์เซิร์ฟเวอร์
สร้างไฟล์ perl รับงานพิมพ์ผ่าน socket
สมมุติว่าเครื่องพิมพ์ชื่อ brother ติดตั้งไดร์ฟเวอร์ไว้เรียบร้อยแล้ว
เราจะสร้างสคริปต์สำหรับรับงานพิมพ์ผ่านทาง socket หมายเลข 5692
# vi /usr/local/bin/brother-print
#!/usr/bin/perl
# Daniel E. Markle
# 20031114 Revision 0.1
# This program starts up a daemon which will watch for a postscript file
# coming in from CUPS, then launch pyla to send it as a fax.
# Use it with the socket://localhost:5691 URL in cups.
# Issues:
# -security, make sure only localhost can see this port, it allows anyone
# who can stream data to this port to popup pyla on your desktop
# -must be ran as the user or the window may not pop up at the right
# place, if at all
# ***CONFIGURE ME HERE
# Port to listen on, use socket://localhost: in cups
my $MY_PORT = 5692;
# Printer name
my $PRINTER = "brother";
# Temporary file storage, this is a file not a folder
my $TMP_FILE_NAME = "/tmp/brotherprint";
# ***END CONFIGURATION
# ----- You shouldn't need to touch anything beyond this point -----
use IO::Socket::INET;
# check to make sure we can use the temp file
open ( TMPFILE, ">", $TMP_FILE_NAME )
or die "Can not open temp file $TMP_FILE_NAME, " .
"check to make sure it is not owned by another user";
close ( TMPFILE );
my $data;
my $server = IO::Socket::INET->new (
LocalPort => $MY_PORT,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 1
) or die "Could not start server process";
while ( my $job = $server->accept() ) {
open ( TMPFILE, ">", $TMP_FILE_NAME );
while ( <$job> ) {
print TMPFILE $_;
}
close ( TMPFILE );
close $job;
`lpr -P "$PRINTER" "$TMP_FILE_NAME"`;
unlink "$TMP_FILE_NAME";
}
สร้างสคริปต์สำหรับเปิดปิดการใช้งาน
เอาไว้ที่ /etc/init.d/ (ไม่ค่อยดีเท่าไหร่ ควรเอาไว้ที่อื่นแล้วสร้างลิงก์มาจะดีกว่า)
# vi /etc/init.d/brother-printd
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/brother-print
NAME=brother-print
DESC="Pseudo printer for Brother"
test -x $DAEMON || exit 0
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--oknodo
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--oknodo
sleep 1
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--chuid $USER --background --make-pidfile \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
สั่งเปิดใช้งานเมื่อเริ่มเปิดเครื่อง และสั่งเปิดใช้งานเลย
# update-rc.d brother-printd defaults
# /etc/init.d/brother-printd start
ที่เครื่องลูกข่าย
เปิดใช้งานด้วยบราวเซอร์ http://localhost:631
ให้ตั้งเครื่องพิมพ์ไปที่ Device URI: socket://server:5692
โดยใช้ไดร์ฟเวอร์เป็น Generic Postscript Printer
หรือสั่งด้วยบรรทัดคำสั่งว่า
$ sudo lpadmin -p brother -E -v socket://server:5692
เสร็จเรียบร้อยแล้ว สามารถพิมพ์ผ่านเครือข่ายได้แล้ว