Unix Shell Scripts for Remote Printing

Do you have any information regarding Unix shell scripts for printing from SystemV to SystemV or from SystemV to BSD and vice versa?
Thank's to Gilles Allain for sending us UNIX scripts that print from SystemV to SystemV or from SystemV to BSD and vice versa. These scripts have been written by Alsys (ADA from A/UX) which is allowing us to freely distribute them.

-----

#!/bin/sh
#########################################################################
#               /usr/spool/lp/model/remote4BSD                          #
#                                                                       #
#       Alsys lp interface for remote printer on 4.xBSD host            #
#       Copyright (C) Alsys, 1987. All rights reserved.                 #
#                                                                       #
# Options recognized:                                                   #
#       nb | -nb        do not output banner page (to save paper)       #
# Other options are passed to remote 4.xBSD lp                          #
#########################################################################

#########################################################################

# Installation instructions for printing on remote 4.xBSD host "Xyz":   #
# - make sure Xyz is correctly reachable by local system's lp:          #
#   - Xyz's /etc/hosts.equiv file must have an entry for local system   #
#   - A user named lp must exist on Xyz                                 #
#   - Xyz's lpr command must recognize the "-h" option                  #
# - create a dummy device file remotelp (needed for scheduler's sake):  #
#       ln /dev/null /dev/remotelp                                      #
# - install this model for "printer" Xyz:                               #
#       /usr/lib/lpadmin -v/dev/remotelp -pXyz -mremote4BSD             #
#########################################################################

# Save the arguments to the model

# Define remote system from "printer" name
remote=`basename $0`
reqid=$1
user=$2
title=$3
copies=$4
tempfile=./request/$remote/$reqid

# Handle disable and cancel traps.

trap "echo '\\nCANCELLED!!';rm -f $tempfile;exit 1" 15

# Determine which options have been invoked


banner="yes"
remoteopts=""

for i in $5
do
       case "$i" in
       -nb | nb) # Do not print banner page
               banner="";;
       *)      # other options passed to remote 4.xBSD lpr
               remoteopts=$remoteopts" "$i;;
       esac
done

# Assume that the rest of the arguments are files

shift; shift; shift; shift; shift
files="$*"

# Redirect output to temporary file

exec > $tempfile

if [ -n "$banner" ]
then
       # Print the header

       x1="  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX
A/UX  A/UX  A/UX  A/UX"
       x2="A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX
A/UX  A/UX  A/UX"
       echo "$x1\\n$x2\\n$x1\\n$x2\\n"
       echo "\\t\\t" `uname -a` "\\n\\n"
       banner "$user"
       echo "\\n"
       banner @`hostname`
       echo '\\n'
       user=`grep "^$user:" /etc/passwd | line | cut -d: -f5`
       if [ -n "$user" ]
       then
               echo "User: $user\\n"
       else
               echo "\\n"
       fi
       echo "Request id: $reqid    Remote printer: $remote\\n"

       date
       echo "\\n"
       if [ -n "$title" ]
       then
               banner "$title"
       fi
       echo "\\r\\c"
fi

# Print the spooled files

i=1
while [ $i -le $copies ]
do
       for file in $files
       do
               cat "$file" 2>&1
               echo "\\r\\c"
       done
       i=`expr $i + 1`
done

# Stop redirection

exec > /dev/null

# Send to remote 4.xBSD system print spooler (without remote banner)

if cat $tempfile | /usr/bin/remsh $remote lpr -h $remoteopts
then
       status=0
else
       status=$?
       disable -r"can't access $remote host" $remote
fi

# Remove temporary file
rm $tempfile

exit $status

-----


#!/bin/sh
#########################################################################
#               /usr/spool/lp/model/remoteSysV                          #
#                                                                       #
#       Alsys lp interface for remote printer on System V host          #
#       Copyright (C) Alsys, 1987. All rights reserved.                 #

#                                                                       #
# Options recognized:                                                   #
#       nb | -nb        do not output banner page (to save paper)       #
# Other options are passed to remote System V lp                        #
#########################################################################

#########################################################################
# Installation instructions for printing on remote System V host "Xyz": #
# - make sure Xyz is correctly reachable by local system's lp:          #
#   - Xyz's /etc/hosts.equiv file must have an entry for local system   #
#   - A user named lp must exist on Xyz                                 #
#   - Xyz's default lp interface model must recognize the "-nb" option  #
# - create a dummy device file remotelp (needed for scheduler's sake):  #
#       ln /dev/null /dev/remotelp                                      #
# - install this model for "printer" Xyz:                               #

#       /usr/lib/lpadmin -v/dev/remotelp -pXyz -mremoteSysV             #
#########################################################################

# Save the arguments to the model

# Define remote system from "printer" name
remote=`basename $0`
reqid=$1
user=$2
title=$3
copies=$4
tempfile=./request/$remote/$reqid

# Handle disable and cancel traps.

trap "echo '\\nCANCELLED!!';rm -f $tempfile;exit 1" 15

# Determine which options have been invoked

banner="yes"
remoteopts=""

for i in $5
do
       case "$i" in
       -nb | nb) # Do not print banner page
               banner="";;
       *)      # other options passed to remote SysV lp
               remoteopts=$remoteopts" -o"$i;;
       esac
done

# Assume that the rest of the arguments are files

shift; shift; shift; shift; shift
files="$*"

# Redirect output to temporary file

exec > $tempfile

if [ -n "$banner" ]
then
       # Print the header

       x1="  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX
A/UX  A/UX  A/UX  A/UX"
       x2="A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX

A/UX  A/UX  A/UX"
       echo "$x1\\n$x2\\n$x1\\n$x2\\n"
       echo "\\t\\t" `uname -a` "\\n\\n"
       banner "$user"
       echo "\\n"
       banner @`hostname`
       echo '\\n'
       user=`grep "^$user:" /etc/passwd | line | cut -d: -f5`
       if [ -n "$user" ]
       then
               echo "User: $user\\n"
       else
               echo "\\n"
       fi
       echo "Request id: $reqid    Remote printer: $remote\\n"
       date
       echo "\\n"
       if [ -n "$title" ]
       then
               banner "$title"
       fi
       echo "\\r\\c"
fi

# Print the spooled files

i=1
while [ $i -le $copies ]
do
       for file in $files
       do
               cat "$file" 2>&1
               echo "\\r\\c"
       done
       i=`expr $i + 1`
done

# Stop redirection

exec > /dev/null

# Send to remote SysV system print spooler (without remote banner)

if cat $tempfile | /usr/bin/remsh $remote lp -onb $remoteopts
then
       status=0
else
       status=$?
       disable -r"can't access $remote host" $remote

fi

# Remove temporary file
rm $tempfile

exit $status

-----


#!/bin/sh
#########################################################################
#                       /usr/local/lib/rsys5lpf                         #
#                                                                       #
#       Alsys "if" lpr input filter for remote printer on SystemV host  #
#       Copyright (C) Alsys, 1988. All rights reserved.                 #
#########################################################################

#########################################################################
# - to be used with a printcap entry of the type:                       #
#       # Remote printer on SystemV host Xyz.                           #
#       Xyz|Xyz|remote printer on Xyz:\\                                 #
#               :lp=/dev/null:if=/usr/local/lib/rsys5lpf:\\              #
#               :af=Xyz:sd=/usr/spool/lpd/Xyz:tr=:                      #
# - kludge needed for this to work: "af" file name must be same as      #

#   remote system hostname (Xyz). Printer name may be different.        #
#########################################################################

# A lpr if filter is invoked with the following arguments:
#       filter [-c] -wWIDTH -lLENGTH -iINDENT -n LOGIN -h HOST ACCOUNTING_FILE
# %%% WARNING: this may vary slightly from one version of lpr to the other;
%%%
# %%% check for your system and modify parameter setup below as appropriate
%%%

# Kludge optional -c argument (-l lpr option)
#    into sort of -h option (suppress banner page)
if [ "$1" = "-c" ]
then
       banner=""
       shift
else
       banner="yes"
fi

# Setup print job parameters from appropriate filter arguments
remote=$8       # kludge: define remote host name from "accounting file" name!
local=$7        # local host name
user=$5         # job owner's login name
userttys=`who | awk '/^'$user'/ {ORS=" ";print $2}'`    # job owner's tty(s)

printfile=/usr/spool/lpd/$remote/pf${$}$remote
messfile=/usr/spool/lpd/$remote/mf${$}$remote

# Handle interrupt traps

trap "echo '\\nCANCELLED!!';rm -f $printfile $messfile;exit 1"  2 15

# Redirect errors to temporary file
exec 2> $messfile

# Redirect output to temporary file
exec > $printfile

if [ -n "$banner" ]
then
       # Print the header
       x1="  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX
A/UX  A/UX  A/UX  A/UX"
       x2="A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX  A/UX
A/UX  A/UX  A/UX"
       echo "$x1\\n$x2\\n$x1\\n$x2\\n"
       echo "\\t\\t\\t" `uname -nrvm` "\\n\\n"
       banner "$user"
       echo "\\n"
       banner @$local
       echo '\\n'
       name=`grep "^$user:" /etc/passwd | line | cut -d: -f5`
       if [ -n "$name" ]
       then
               echo "User: $name\\n"
       else
               echo "\\n"
       fi
       echo "Remote printer: $remote\\n"
       date
       echo "\\n"
       echo "\\f\\r\\c"
fi

# "Print" the spooled file to temporary file
cat 2>&1

# Stop output redirection
exec >&2
echo "\\nlpr: $remote: \\c"

# Send to remote SysV system print spooler (without remote banner)

# %%% this supposes that remote spooler's default lp interface model    %%%
# %%% recognizes "-nb" option for banner suppression (modify if needed) %%%
if cat $printfile | /usr/bin/remsh $remote lp -onb
then
       status=0
else
       status=2
       echo "lpr: can't access $remote host"
fi

# Send message to job owner's tty(s)
for usertty in $userttys
do
       cat $messfile > /dev/$usertty
done

# Remove temporary files
rm -f $printfile $messfile

exit $status



Article Change History:
07 Sep 1994 - Reviewed.
31 Aug 1992 - REVIEWED for technical accuracy.

Support Information Services


Published Date: Feb 18, 2012