Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create printers on unix within a function

Status
Not open for further replies.

grapes12

Technical User
Joined
Mar 2, 2010
Messages
124
Location
ZA
I need assistance on creating ,deleting printers within a function herwith is what i have
Code:
#!/bin/ksh
BIN=/usr/lbin
LOCAL_FILE=`$BIN/lpstat -v >> sun5-printers.txt
REMOTE_FILE=`rsh sun8 /usr/lbin/lpstat -v >> sun8-printers.txt
awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ }}{ if (!($0
 in arr ) ) {print} }' sun8-printers.txt

#Amend,create or delete Printer

prExists=$?
function printerExists()
{
prName=" "
prAddress=" "
prLocation=" "
prdescrip=" "
prfilter=" "
prport=" "
prdriver=" "
   if [ $prExists -eq 1 ]; then
        echo "\n\t Printer already exists. "
   else
        echo
        $BIN/lpadmin -x $Prname
        echo "\n\t Deleting printer $Prname !!!"
   fi
  # Add Printer Command 
  lpadmin -p "${prName}" -E -D "${prDescript}" -L "${prLocation}" -i /u1/cups/mac/"$prFilter_filter -v \
  "$Prdriver"://"${prAddress}":"Prport"
fi

Any assistance will be highly appreciated
 
hi moreFeo,
Got my function working! Here is what it looks like:
Code:
f_Delete()
{
 if [ -z "$printer" ]; then
      echo "\n\t Nothing to be deleted!"
      return 1
   else
      for P in $printer; do
      echo "\n\t Deleting printer $P !!!"
      $BIN/lpadmin -x $P 2> /dev/null
      done
      return 0
 fi
}
Output received:
[code]
117bd1 2201bl7 5001bl1
+ f_Delete

         Deleting printer 0117bd1 !!!

         Deleting printer 2201bl7 !!!

         Deleting printer 5001bl1 !!!

Now to recreate the printers!
herewith is my function:
Code:
f_Create()
{
  if [ -z "$printer" ]; then
       echo "\n\t $printer does not exists"
       return 1
    else
    for P in $printer; do
    echo "\n\t Adding printers !!!!"
    echo "Enter Printer Name: \c"
    read printer
    echo "Enter IP Address  : \c"
    read ip
    echo "Enter Location    : \c"
    read loc
    echo "Enter Description : \c"
    read desc
    echo "Enter Filter      : \c"
    read filt
    echo "Enter Port        : \c"
    read port
    echo "Enter Driver      : \c"
    read driv
    $BIN/lpadmin -p "$printer" -E -D "$desc" -L "$loc" -i /u1/cups/mac/"$filt"_fi
lter -v "$driv"://"$ip":"$port"
    done
    echo "\n\t Printer $printer created"
 fi
}

 
Script is hanging when during execution of create function???
Code:
#!/bin/ksh
BIN=/usr/lbin/
LOCAL_FILE=`$BIN/lpstat -v > sun5-printers.txt`
REMOTE_FILE=`rsh sun8 /usr/lbin/lpstat -v > sun8-printers.txt`
#DIFF_FILE=/usr/local/bin/diffs.txt

awk 'BEGIN {while ( getline < "sun5-printers.txt") {arr[$0]++ } } { if (!($0 in a
rr ) ) { print } }' sun8-printers.txt > diffs.txt

for i in `cat diffs.txt`
do
printer="$(awk -F: '{ print $1 }' | cut -c 11-18 diffs.txt)"
echo $printer
done
#done < diffs.txt

#Amend,create or delete Printer

f_Delete()
{
 if [ -z "$printer" ]; then
      echo "\n\t Nothing to be deleted!"
      return 1
   else
      for P in $printer; do
      echo "\n\t Deleting printer $P !!!"
      $BIN/lpadmin -x $P 2> /dev/null
   done
      return 0
 fi
}

f_Create()
{
  if [ -z "$printer" ]; then
       echo "\n\t $printer does not exists"
       return 1
    else
    for P in $printer; do
    echo "\n\t Adding printers !!!!"

    echo "Enter Printer Name: \c"
    read printer
    echo "Enter IP Address  : \c"
    read ip
    echo "Enter Location    : \c"
    read loc
    echo "Enter Description : \c"
    read desc
    echo "Enter Filter      : \c"
    read filt
    echo "Enter Port        : \c"
    read port
    echo "Enter Driver      : \c"
    read driv
    $BIN/lpadmin -p "$printer" -E -D "$desc" -L "$loc" -i /u1/cups/mac/"$filt"_fi
lter -v "$driv"://"$ip":"$port"
    done
    echo "\n\t Printer $printer created"
  fi
}

f_Delete
f_Create

Is there incorrect syntax????
please assist!!!!
 
Where is it hanging? Does it show something at all?
 
It hangs in the create function, right after entering the printer name!
 
Morefeo...
any suggestions
 
The pressure is mounting.The script is still hanging When i add the printer to be created.Any help will be highly appreciated.
herewith is the function i am calling:
Code:
f_Create()
{
set -x
  if [ -z "$printer" ]; then
         echo "\n\t $printer does not exists"
       return 1
    else
       for P in $printer; do
        echo "\n\t Adding printers !!!!"

    echo "Enter $Printer Name: \c"
    read printer
    echo "Enter IP Address  : \c"
    read ip
    echo "Enter Location    : \c"
    read loc
    echo "Enter Description : \c"
    read desc
    echo "Enter Filter      : \c"
    read filt
    echo "Enter Port        : \c"
    read port
    echo "Enter Driver      : \c"
    read driv
    $BIN/lpadmin -p "$printer" -E -D "$desc" -L "$loc" -i /u1/cups/mac/"$filt"_fi
lter -v "$driv"://"$ip":"$port"
    done
    echo "\n\t Printer $printer created"
  fi
}

PLEASE
 
Removed the read printer,read IP etc
Printers are now created without the required parameters
function looks now like this
Code:
f_Create()
{
set -x
  if [ -z "$printer_list" ]; then
         echo "\n\t $printer does not exists"
       return 1
    else
       for P in $printer_list; do
        echo "\n\t Adding printers !!!!"

    $BIN/lpadmin -p "$P" -E -D "$desc" -L "$loc" -i /u1/cups/mac/"$filt"_filter -
v "$driv"://"$ip":"$port"
    done
    echo "\n\t Printer $printer created"
  fi
}

I still need some parameters, which i want to use as variables to re-create printers.
any suggestions
 
mut be a long weekend??? still no response..any asisstance will be highly appreciated...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top