If this isn't exactly what you wanted, please try our Search (there's a LOT of techy and non-techy stuff here about Linux, Unix, Mac OS X and just computers in general!):
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.
Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)
| Views for this page | ||||
|---|---|---|---|---|
| Today | This Week | This Month | This Year | Overall |
| 3 | 5 | 19 | 391 | 1,795 |
/Bofcusm/1314.html copyright 1997-2004 (various authors) 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.

Add your comments