Solved

Script help

Posted on 2002-07-29
1
580 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 168
Red Hat Enterprise Linux 6.5 gets missing "/lib/ld-linux.so.2" 7 112
Sed question 2 122
unix solaris snoop command 6 122
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

713 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