Technical:DefaultPrinterBasedOnLocation

From K12LTSP Wiki

Jump to: navigation, search

In some cases, it is convenient to have a user's default printer be determined by which client workstation is being used. The following message from Henry Burroughs to the mailing list describes a shell script he wrote to do just this. The script is printed below the message.


Hi everyone==== I don't know if this is already been done, but I have ==== created a script that will set the default printer based on which client you are logged in as (ie: if you have multiple labs off one server and printers in each of those labs).

You just drop setprinter.sh into your /etc/profile.d/ directory, and create a /etc/sysconfig/ltsp_printers with information like this:

printer-que:ws100,ws101,ws102,ws103 printer-que2:ws200,ws201,ws202

You don't have to list all your clients; it will keep whatever the last que was for a user when they log into that client.

This is a good question for everyone... should it reset the que back to the server default if that client isn't listed above?

You can overide the default printer during your session (it will not be reset if you open a terminal due to a SETPRINTER=true env variable which keeps the script from running more than once during a user's session).

Also, you don't have to create a ltsp_printers file, which means the script doesn't do anything (and it shouldn't puke up errors either

knock on wood::).

<verbatim>

  1. ====/bin/bash ====
  2. This script helps set the printers up....
  3. Checks the file ltsp_printers in /etc/sysconfig for configuration
  4. Format of the file is this:
  5. printer-que:host,host,host


  1. Need to see if it has been run....

if ==== "$SETPRINTERS" ; then ====

       SETPRINTERS=true
       export SETPRINTERS=$SETPRINTERS

else

       return

fi

HOSTNAME=`echo ${DISPLAY} || cut -f1 -d: || awk -F . {' print $1 '}`

  1. If DISPLAY is not set...stop...don't need to configure printing

if ==== "$DISPLAY" ; then ====

       return

fi

DATA=`cat /etc/sysconfig/ltsp_printers 2> /dev/null`

  1. If the file doesn't exist, exit

if $? -eq 1 ; then

       return

fi

for entry in $DATA do

       #Printer que is:
       PRINTER=`echo $entry || cut -d: -f1`
       HOSTLIST=`echo $entry || cut -d: -f2`
       for host in `echo $HOSTLIST || sed 's/,/ /g'`
       do
               if  $host = $HOSTNAME ; then
                       lpoptions -d $PRINTER > /dev/null
               fi
       done

done </verbatim>

Personal tools