Using nc as a pseudo raw print server


Well-Known Member

Reaction score: 27
Messages: 426

I am experimenting with establishing a raw print service to route printer output from a legacy computer system through a CUPS server. The information I have been given or have found points towards using the nc utility. I was able to get the nc utility to listen on a port and receive data on it when run in the foreground using nc -lk 9100. This accepts multiple connection sessions and remains running between each.

The command I use for the listener is: /usr/bin/nc -lk 9100 >> /var/spool/nc9100/nc9100.txt &. For this to go further I have to daemonize this. I have the daemonize port and I have tried this:
daemonize -v \
  -c /var/spool/nc9100 \
  -e /var/log/cups/nc9100_error.log \
  -l /var/run/cups/nc9100.lock \
  -p /var/run/cups/ \
  -u cups /usr/bin/nc  -lk 9100 >> /var/spool/nc9100/nc9100.txt

Which does not give the same results as when nc is run in the background of a user session. What am I doing wrong? Ultimately I expect that I will pipe the output to a local cups printer but for now I just want to get the input into a local file.



Reaction score: 32
Messages: 38

Try -u cups /bin/sh -c '/usr/bin/nc -lk 9100 >> /var/spool/nc9100/nc9100.txt'

socat is much better suited for these kinds of tasks. I use it myself to redirect 9100 to a USB printer 😎