#!/bin/sh ###################################################### ## NAME: ## ## printer - add/remove remote printers ## ## SYNOPSIS ## ## printer -add hostname printername [localname] ## printer -remove printername [printername...] ## ## ARGUMENTS ## ## ## DESCRIPTION ## ## NOTES ## ## Will not operate on printers directly connected ## ############################################### ## #FULLDOMAIN="digicon-hou.com" #FULLDOMAIN="vdgc.com" THISHOST="`hostname`" # Help message if [ "$1" = "-h" -o "$1" = "-help" -o $# -lt 2 ]; then cat $0 | grep "^##" exit fi if [ "$1" = "-add" ]; then FLAG="add" shift elif [ "$1" = "-remove" ]; then FLAG="remove" shift PRINTERS="$*" else echo "ERROR: enter the -add or -remove option" exit fi if [ "$1" != "" ]; then # HOST="$1.$FULLDOMAIN" HOST="$1" shift if [ "$HOST" = "$THISHOST" ]; then echo "script will not work on local printers. exiting" exit 1 fi fi if [ "$1" != "" ]; then PRINTER="$1" shift fi if [ "$1" != "" ]; then LPRINTER="$1" shift else LPRINTER="$PRINTER" fi if [ "$FLAG" = "add" ]; then echo "Adding Remote Printer: $LPRINTER" /usr/sam/lbin/lpmgr -a -xlocalname=$LPRINTER,default=n,fence=0,rc=y,is_bsd=n,remname=$PRINTER,remsys=$HOST,remcancel=rcmodel,remstatus=rsmodel if [ $? != 0 ]; then echo "lpmgr failure exiting" # exit 1 fi echo "Stopping the lp scheduler" /usr/sbin/lpshut if [ $? != 0 ]; then echo "lpshut failure exiting" # exit 1 fi sleep 2 echo "Adding the printer $LPRINTER to the lp spooler" /usr/sbin/lpadmin -p$LPRINTER -orm$HOST -orp$PRINTER -mrmodel -v/dev/null -orc -ocmrcmodel -osmrsmodel if [ $? != 0 ]; then echo "lpadmin failure exiting" # exit 1 fi echo "Accepting print requests" /usr/sbin/accept $LPRINTER echo "Enabling Printer" /usr/bin/enable $LPRINTER echo "Starting the lp scheduler with logging turned off" /usr/sbin/lpsched if [ $? != 0 ]; then echo "lpsched failure exiting" exit 1 fi elif [ "$FLAG" = "remove" ]; then echo "Removing Remote Printer: $LPRINTER" echo "Stopping the lp scheduler" /usr/sbin/lpshut if [ $? != 0 ]; then echo "lpshut failure exiting" # exit 1 fi sleep 2 for XPRINTER in $PRINTERS; do echo "Removing the printer $XPRINTER from the lp spooler" /usr/sbin/lpadmin -x$XPRINTER if [ $? != 0 ]; then echo "lpadmin failure exiting" # exit 1 fi done echo "Starting the lp scheduler with logging turned off" /usr/sbin/lpsched if [ $? != 0 ]; then echo "lpsched failure exiting" exit 1 fi fi