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
Solved

Script help

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.:
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…

829 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