Solved

Script help

Posted on 2002-07-29
1
565 Views
Last Modified: 2008-02-01
Hi
I have this script which I think creates a virtual printer
I need to print to |lp -dmyprinter this will actually print to the printer attached to my wy50 terminal
How do I use this script
:
###################################################
#                                                 #
# Unix Transparent Printer Driver - Version 1.2   #
#                                                 #
###################################################
#                                                 #
# Contributors : David Shakespeare                #
#                Conrad Gonsalves                 #
#                Indy Pank                        #
#                                                 #
# Date    : 31st July 1991                        #
#                                                 #
#                                                 #
# Supports The Following Terminals :-             #
#                                                 #
# Altos3, Altos4, Altos5, Altos7 (Liberty)        #
# Wyse50, Wyse60, Wyse120, Wyse350                #
# DEC VT100.                                      #
#                                                 #
# Gets Terminal Description From /etc/xprt        #
# eg tty5 would have a file /etc/xprt/tty5        #
# this file contains the ttytype eg wyse50        #
#                                                 #
# Don't forget to set your screen to xon/xoff     #
#                                                 #
###################################################

printer=`basename $0`
request=$1
name=$2
title=$3
copies=$4
options=$5
portname=`lpstat -v | grep $printer | awk -f: '{ print $2 }'`
portname=`basename $portname`
okay=yes
tranproc='sh getty'

# is there a sh or a getty on this port ?

TPORT=no
for i in $tranproc
do
      rm -f /tmp/$$
      if [ $TPORT = no ]
      then
            ps -t $portname | grep $i >/tmp/$$
            if [ -s /tmp/$$ ]
            then
                  TPORT=yes;proctype=$i
            fi
      fi
done

if [ $TPORT = yes ]
then
      # some sort of login process running

      if [ -r /etc/xprt/$portname ]
      then
            # description file available
            # PRINTON is "lock keyboard" then "go into transparent"
            # PRINTOFF is "go into normal" then "unlock keyboard"

            case `cat /etc/xprt/$portname` in
                     altos3)      PRINTON=`echo "\033[?2h\033[5i\c"`
                                PRINTOFF=`echo "\033[4i\033[?2l\c"`;;
                     altos4)      PRINTON=`echo "\033#\033~\"\030\c"`
                                PRINTOFF=`echo "\030\033\"\c"`;;
                     altos5)    PRINTON=`echo "\033[?2h\033[5i\c"`
                                PRINTOFF=`echo "\033[4i\033[?2l\c"`;;
                     wyse50)    PRINTON=`echo "\033\043\033\0144\043\c"`
                                PRINTOFF=`echo "\024\033\"\c"`;;
                    liberty)    PRINTON=`echo "\030\033\043\c"`
                                PRINTOFF=`echo "\024\033\042\c"`;;
                     wyse60)    PRINTON=`echo "\033#\033d#\c"`
                                PRINTOFF=`echo "\024\033\"\c"`;;
                     wyse85)    PRINTON=`echo "\033[2h\033[5i\c"`
                                PRINTOFF=`echo "\033[4i\033[2l\c"`;;
                    wyse120)    PRINTON=`echo "\033#\033d#\c"`
                                PRINTOFF=`echo "\024\033\"\c"`;;
                    wyse350)    PRINTON=`echo "\033#\030\c"`
                                PRINTOFF=`echo "\024\033\"\c"`;;
                      vt100)    PRINTON=`echo "\033[2h\033[5i\c"`
                                PRINTOFF=`echo "\033[4i\033[2l\c"`;;
                          *)      okay=no
                        message="* Terminal not supported *" ;;
            esac
      else
            # no description file
            portname=unknown
            okay=no
            message="* Port Description not set *"
      fi
else
      portname=unknown
fi

rm -f /tmp/$$
shift; shift; shift; shift; shift

#Default options
ff=yes
opost=yes

#Extract options
for opt in $options
do
      case $opt in
      N)      ff=no ;;
      S)      opost=no ;;
      esac
done

# If it is necessary to change the baud rate or other stty settings for
# your serial printer
if [ $TPORT = no ]
then
      stty 9600 raw -echo 0<&1
      stty opost onlcr ixon ixoff -tabs 0<&1
fi

# small stty seems to be necessary if terminal is at getty

if [ "$proctype" = "getty" ]
then
      # store old stty & set new one
      stty -g 0<&1 >/tmp/$$
      sttysettings=`cat /tmp/$$`;export sttysettings
      stty -echo opost onlcr ixon ixoff -tabs 0<&1
      rm -f /tmp/$$
fi

# if TPORT=no print as normal,if TPORT=yes and TERM=unknown, send error
# message to port.
 
if [ $okay = no ]
then
      echo
      echo "*****************************"
      echo "*                           *"
      echo "$message"
      echo "*                           *"
      echo "*****************************"
else
      # OK to print
      if [ $TPORT = yes ]
      then
            # send aux port string
            echo $PRINTON"\c"
      fi
      

      # send the file(s) to the standard out $copies times
      while      [ "$copies" -gt 0 ]
      do
            for file
            do

                  # send -opost if printing from SCO

                  if [ $opost = no ]
                  then
                        stty -opost 0<&1
                  fi

                  cat "$file" 2>&1

                  # send opost if printing from SCO

                  if [ $opost = no ]
                  then
                        stty opost 0<&1
                  fi

                  if [ $ff = yes ]
                  then
                        echo "\f\c"
                  fi
            done
            copies=`expr $copies - 1`
      done
      if [ $TPORT = yes ]
      then
            # send aux port close
            echo $PRINTOFF"\c"
            # if it was a getty, restore stty settings
            if [ "$proctype" = "getty" ]
            then
                  stty $sttysettings 0<&1
            fi
      fi
fi
exit 0

0
Comment
Question by:bluez
1 Comment
 
LVL 20

Accepted Solution

by:
tfewster earned 100 total points
ID: 7186574
I believe you need to create a printer with this script as the driver and /dev/tty_of_target_terminal as the device. Then anyone can send to that printer.

The script then gets the tty id, checks the terminal type, sends the PRINTON string, cats the file (passed through to the printer) and tidies up with PRINTOFF.

Oddly, $file doesn't seem to get initialised within the script, so I'm not sure where it takes its data from. Maybe the lp spooler exports $file.

If you don't have admin rights, you can still send to your printer by using:
echo "\033\043\033\0144\043\c"
cat $file
echo "\024\033\"\c"

(or amending the script to 'fix' $portname and cut out any unused variables so you could use it as `my_print_script copies filename`)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sed -- search an replace multiple pattern 11 74
Convert OverPunch 25 63
Problem logging tar errors 11 57
mobaxterm not able to change directory 28 145
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now