I have a similar situation where I have 6 modems used as a dialin pool, and the users always don't hit the same modem every time so I can't lock their local printing to a specific port.
What I have done to resolve this is I identify the port by a "who" command within the printer interface itself, which I pipe through "awk".
Hopefully you are somewhat familiar with printer interface scripts. Here is a sample of my interface script for local printing:
Code:
termport=`who | awk '{if ($1==id) {printf("/dev/%s",$2);exit(0)}}' id=$2`
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#identify the terminal tty port
#Note: The line above must occur before the $2 'user id' parameter is cleared
shift; shift; shift; shift; shift #clear print job options to prepare for print
penable="\033[5i" #string to turn printer output on
pdisable="\033[4i" #string to turn printer output off
sttystr="ixon -ixany ixoff" #string to configure printer flow control
sleep 5 #wait 5 seconds to let any screen draws finish
exec <$termport >$termport 2>/dev/null #redirect standard out to printer
sttysave=`stty -g` #save terminal settings
stty $sttystr #turn on printer flow control
echo -n "$penable" #turn on printer output
...
#spool print job to standard out#
...
echo -n "$pdisable" #turn off printer output
stty $sttysave #restore terminal settings
exit 0 #exit interface script
This allows local terminal printing to an unfixed port using an ordinary interface file.
There are two disadvantages to this method:
First, the interface can only manage printing to one port at a time, so if user A tries to print while user B is printing to the same interface, user A's job will not start until user B's job is completed. The easiest solution to this is to give each user their own printer interface.
Second, if a user is logged in more than once, the print job is always sent to the smallest port number they are connected to, which may not be the same port as the job originated from. Unfortunately the lp command does not remember the originating ttyport, only the user id, so there really isn't a better solution for this.