Solved

Script help

Posted on 2002-07-29
1
583 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

734 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