Using Netcat for a simple lpr client

By Carsten Hammer

Are you looking for FAQ: what is netcat and how do I use it?

Editor's note:

Some print servers simply print whatever data is presented to them. For example, the HP Jet Direct and many other print servers work that way. See /SCOFAQ/scotec7.html#getnetcat for more on that.


Hate these ads?

LPD style printers require more of a protocol. Carsten Hammer has presented a simple shell script that provides that protocol.

The netcat Carsten uses in this script is the Linux version that has many more features than the simple SCO binary referred to above, but either could be used with this script- just leave out the flags that aren't used if you have the simpler version.


If you like you can even use a simple shell/awk-script to build a lpr like client arount netcat.

It looks like this:



#!/bin/sh
# Simple pseude lpr-like client for transmission of arbitrary controlfile
# parameters
# Carsten Hammer <Hammer.Carsten@oce.de>, 2002
#set -x
# Programmname zielhost queuename
# Counter maintained in /tmp/nr








echo "Host:" $1
echo "Queue:" $2
echo "Dateiname:" $3



Size=`ls -lL $3|tr -s ' '|cut -d' ' -f5`
echo "Dateigr�sse:" $Size



# netcat
NC=/usr/local/bin/nc



awkscript="BEGIN {
n=sprintf(\"%03d\",ARGV[2] +0);
size=sprintf(\"%d\",ARGV[3] +0);
queuename=ARGV[1]
c=c \"HSYSM\n\"
c=c \"PSAF0006\n\"
c=c \"fdfA\"n\"SYSM\n\"
c=c \"UdfA\"n\"SYSM\n\"
c=c \"NDEFSYSM.SAF0006.SAF00066.JOB07513.D0000103.?\n\"
c=c \"-odatat=l\n\"
c=c \"-ofileformat=record\n\"
c=c \"-occ=yes\n\"
c=c \"-oro=e\n\"
c=c \"-occtype=a\n\"
c=c \"-ochars=315A\n\"
c=c \"-ocop=001\n\"
c=c \"-ous=SAF0006\n\"
c=c \"-ono=DEFSYSM\n\"
c=c \"-opr=AUGUST\n\"
c=c \"-opa=forms=STD,class=8,destination=PWSCHU01\n\"



clen=sprintf(\"%04d\",length(c))
ca=ca\"\002\"queuename\"\n\"
ca=ca\"\002\"clen\" cfA\"n\"SYSM\n\"
e= \"+\"
da=da \"\003\"size\" dfA\"n\"SYSM\n\"
e= \"+\"
printf ca
printf c
printf e
printf da
}"






if [ ! -f "/tmp/nr" ] ; then echo "1" >/tmp/nr; fi
awk '{ print $1+1 }' /tmp/nr.bak;mv /tmp/nr.bak /tmp/nr
{ awk "$awkscript" "$2" "`cat /tmp/nr`" "$Size"|tr '+' '\000';cat $3;printf
'\000';}|\
$NC -v -v  -w 2 -o bla.log $1 515




# print any waiting jobs
#printf "\001blubb\n" | $NC -v localhost 515
# send queue state (short)
#printf "\003blubb\n" | $NC -v localhost 515
# send queue state (long)
#printf "\004blubb\n" | $NC -v localhost 515
#printf "\004oce\n" | $NC -v localhost 515







Comments /Unixart/netcatlpr.html
UnixartNetcatlpr :

---October 24, 2004



Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
1199804 15,356

/Unixart/netcatlpr.html copyright September 2002 Carsten Hammer All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

More:
       - Administration
       - Code
       - Networking
       - Printing
       - Programming




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.cleverminds.net Need expert advice? Want a second opinion? CleverMinds is a one-stop-shop for a wide range of technology solutions. We support Unix, Linux, SCO as well as CMS, ecom, blogs, podcasts, search engines consulting and more. Contact us at web2.0@cleverminds.net 0r (617) 894-1282


SCO, OpenServer, UnixWare, software, servers, security, networks, installation, administration, troubleshooting, maintenance, Watchguard, firewalls, VPNs, e-mail. Visit us at http://opensystemscomputing.com and www.go2unix.com.


http://www.breakthru.com.au SCO (Openserver and Unixware), Unix, Solaris and Linux Consulting services including: Secure Networking Solutions; Linux based Firewalls; Backup Solutions; Secure Home to Office Network Setup; Phone, Remote and On-Site Support available - Satisfaction Guaranteed!




card_image








Change Congress

Related Posts