?

Log in

Script for add Windows Network Printer to Linux - Unix-Solution [entries|archive|friends|userinfo]
Unix-Solution

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Script for add Windows Network Printer to Linux [Aug. 31st, 2006|10:48 am]
Unix-Solution

unix_solution

[maximum_value]
for example:
  Windows machine name = val
  Windows printer sharename = 2100val
  Printer type = HP-LaserJet_2100
  Printer Driver = hpij
  Printer Username and Password = printeruser and Printer (local or in Active Directory)

add to /etc/sudoers:

%users ALL=(root) NOPASSWD: /usr/bin/foomatic-configure

or

%Domain\ Users ALL=(root) NOPASSWD: /usr/bin/foomatic-configure (for AD)


Tested on Ubuntu 6.06


/usr/local/bin/inst_smb_printer.sh:

#!/bin/sh
# inst_smb_printer.sh path printername driver
# example: inst_smb_printer.sh val/2100val HP-LaserJet_2100 hpij

if [ $# != 3 ]; then exit; fi

path=$1
printer=$2
driver=$3
printername=`echo $path | sed 's/\//_/'`
localprintername=`foomatic-configure -Q | grep -o "$printername"`
remove="foomatic-configure -n $printername -R"
install="foomatic-configure -s cups -n $printername \
-p $printer -d $driver \
-c smb://printeruser:Print@$path"

if [ "$localprintername" == "$printername" ]; then
        gksudo "$remove" > /dev/null |\
        zenity --progress --text="Удаление принтера" --percentage=40 --auto-close &&\
        zenity --info --text="Принтер удалён" ||\
        zenity --info --text="Произошла ошибка при удалении принтера, позвоните в АСУ"
else
        (gksudo "$install" > /dev/null && echo 80 &&\
        foomatic-configure -D -n $printername > /dev/null &&\
        zenity --info --text="Принтер установлен" ||\
        zenity --info --text="Произошла ошибка при установке принтера, позвоните в АСУ") |\
        zenity --progress --text="Установка принтера" --percentage=40 --auto-close
fi
linkReply