The 'netcat' referred to here is a simple C program (SCO systems) for direct writing to specified ports - see Where do I get "netcat" and how do I use it?
It was very useful on SCO systems because they used a complicated HP binary that often caused problems. Netcat was simple, direct and problem-free.
Note that this is calling "lpadmin" to create new printers.
From: Steve Fabac <smfabac@att.net> Subject: Netcat again Date: Thu, 20 Dec 2001 06:16:25 GMT Boy, I like netcat. Just finished converting one client's SCO 5.0.5 system from Berkeley LPD to netcat and recommend the change to anyone now using LPD to print to dedicated print servers. I cobbled the following script to parse the /etc/printers file and automatically setup one or all printers. I also include my version of HPLaserJet.net supporting duplex enable printers, 66 line portrait and 66 line landscape as well as 88 line 16.6cpi portrait.
The netcat documentation suggests port 9101 and others, but when I
tried 9101 with the HPJetdirect cards and Lexmark printers, the jobs
hang and don't print. Each of the print servers at the client's site
were single port, So I have not addressed the problem of printing to
stand alone servers with multiple parallel ports for two or more
printers.
If you use netcat and have information on other printer port settings
that work, I would like to hear from you.
--
Steve Fabac
S.M. Fabac & Associates
816/765-1670
>/usr/local/bin/printeradmin:
option=$1
tprinter=$2
[ -z "$option" ] || opt="opt=$1"
[ -z "$tprinter" ] || printer="ptr="$2
awk ' BEGIN { FS = ":" }
{
# print ARGC, ARGV[0], ARGV[1], ARGV[2] , ARGV[3], ARGV[4]
if ( ARGC < 3 ) {
printf "\n\n Usage: printeradmin add <- create all printers in /etc/printers\n printeradmin delete <- delete all printers in /etc/printers\n\n"
printf "\n\n Usage: printeradmin add name <- create named printer in /etc/printers\n printeradmin delete name <- delete named printer in /etc/printers\n\n"
exit
}
if ( ARGC == 3 ) {
if ( NF == 4 ) {
if ( opt == "add" ) {
printf "/usr/lib/lpadmin -p %s -v /dev/null -m HPLaserJet.net -D \042%s\042\n", $1, $4
printf "/usr/lib/accept %s\n", $1
printf "enable %s\n", $1
}
if ( opt == "delete" ) {
printf "/usr/lib/lpadmin -x %s \n", $1
}
}
}
if ( ARGC == 4 ) {
if ( NF == 4 ) {
if ( opt == "add" && ptr == $1 ) {
printf "/usr/lib/lpadmin -p %s -v /dev/null -m HPLaserJet.net -D \042%s\042\n", $1, $4
printf "/usr/lib/accept %s\n", $1
printf "enable %s\n", $1
}
if ( opt == "delete" && ptr == $1 ) {
printf "/usr/lib/lpadmin -x %s \n", $1
}
}
}
} ' $opt $printer /etc/printers
printeradmin writes its output to standardout and does not execuite
the commands. I just run printeradmin > /tmp/doit and then
"sh /tmp/doit" after I page /tmp/doit to see that it's correct.
>HPLaserJet.net:
:
# @(#) hpjet.src 1.2 88/05/13
#
# Copyright (C) The Santa Cruz Operation, 1985, 1986.
# This Module contains Proprietary Information of
# The Santa Cruz Operation, Microsoft Corporation
# and AT&T, and should be treated as Confidential.
#
#! HP Laserjet, Thinkjet or QuietJet
#
printer=`basename $0`
request=$1
name=$2
title=$3
copies=$4
options=$5
shift; shift; shift; shift; shift
spool=/usr/spool/lp
FILTER="xtod | ${spool}/bin/ffstrip"
# Look for HOST and Port address
PRTSETUP=`grep "^$printer:" /etc/printers`
if [ $? = 0 ]
then
PRTHOST=`echo $PRTSETUP|awk -F: '{ print $2 }'`
PRTPORT=`echo $PRTSETUP|awk -F: '{ print $3 }'`
else
exit 1
fi
# border around the banner
x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Graphics=no
Landscape=no
Wide=no
banner=no # I don't use banners, have not tested banner=yes
sixlines=no
tencpi=no
Duplex=no
for i in $options
do
case $i in
raw|g|G|pro) Graphics=yes
;;
l|L) Landscape=yes
;;
d|D) Duplex=yes
;;
w|W) Wide=yes
;;
nobanner|b) banner=no
;;
6lpi) sixlines=yes
;;
10cpi) tencpi=yes
;;
esac
done
#
# Set up FILTER environment variable.
#
#
: ${SPOOLDIR:=/usr/spool/lp}
: ${LOCALPATH:=${SPOOLDIR}/bin}
if [ ! -x "${LPCAT:=${LOCALPATH}/lp.cat}" ]
then
LPCAT="cat"
fi
if [ "$Graphics" = "yes" ]
then
FILTER="${LPCAT} 0"
fi
(
if [ "$Landscape" = yes ]
then
echo "\033E\033&l1o5.45c66F\033(s16.66H\c"
[ "$tencpi" = yes ] && echo "\033(s10H\c"
elif [ "$Wide" = yes ]
then
echo "\033E\033&l0o5.47c88F\033(s16.66H\c"
else
echo "\033E\033&a0L\033&l0o7.27c66F\c"
fi
if [ "$Duplex" = "yes" ]
then
echo "\033&l1S\c"
else
echo "\033&l0S\c"
fi
if [ "$sixlines" = yes ]
then
echo "\033&l6D\c"
fi
[ "$banner" = yes ] && {
# get the local system id
if test -r /etc/systemid; then
sysid=`sed 1q /etc/systemid`
else
sysid=`uname -n`
fi
# user = fifth field of /etc/passwd
user=`sed -n "s/^$name:.*:.*:.*:\(.*\):.*:.*$/\1/p" /etc/passwd`
# nhead gets the value of BANNERS or 1 by default
nhead=`sed -n 's/^BANNERS=//p' /etc/default/lpd`
[ "$nhead" -ge 0 -a "$nhead" -le 5 ] || nhead=1
# print the banner $nhead times
while [ "$nhead" -gt 0 ]
do
echo "$x\n"
banner "$name"
echo "$x\n"
[ "$user" ] && echo "User: $user\n"
echo "Request id: $request\n"
echo "Printer: $printer\n"
echo "Options: $options\n"
date
echo "\nMachine: $sysid\n"
[ "$title" ] && banner $title
echo "\f\c"
nhead=`expr $nhead - 1`
done
}
# send the file(s) to the standard out $copies times
while [ "$copies" -gt 0 ]
do
for file
do
0<${file} eval ${FILTER}
done
copies=`expr $copies - 1`
done ) | /usr/local/bin/netcat -h $PRTHOST -p $PRTPORT
sleep 1
exit 0
> Modified /etc/printers:
printer:printserver host:port
laser1:hpnet1:9100:HP 4050D in accounting
boblaser:hpnet2:9100:Lexmark T522N 192.168.10.20
The comment field was added and these comments appear as printer
comments with the scoadmin printer screen.
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.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar