Solved

Script help

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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.:
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.

757 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

19 Experts available now in Live!

Get 1:1 Help Now