+ f_Delete
resync-printers.ksh[2]: test: argument expected
lpadmin: Expected printer or class after '-x' option!
resync-printers.ksh[7]: test: argument expected
+ f_Create
resync-printers.ksh[2]: [0: not found
lpadmin: The printer-uri must be of the form "ipp://HOSTNAME/printers/PRINTERNAME
".
Printer created
f_Delete()
{
if ["$printer" -ne 1 ]; then
echo "\n\t $printer to be deleted"
return 0
else
$BIN/lpadmin -x $printer
if [ $printer = " ${printer}" ]; then
echo "\n\t Deleting printer $Printer !!!"
return 1
fi
fi
}
I suspect that there is some syntax errors within this function but not sure where?
Good, added the space and it worked...but not doing the first function by deleting the printer with lpadmin -x command.
i did use the ticks as its a unix command
f_Delete()
{
if [ "$printer" -ne 0 ]; then
echo "\n\t Printer to be deleted"
return 0
else
`$BIN/lpadmin -x $printer`
echo "\n\t Deleting printer $Printer !!!"
Here is the current error received when running the script:
+ echo 0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
+ f_Delete
resync-printers.ksh[2]: 0117bd1^J 2201bl7^J 5001bl1: bad number
Deleting printer !!!
f_Delete()
{
if [ -z "$printer" ]; then
echo "\n\t Printer to be deleted"
return 1
else
for P in $printer; do
echo "Deleting printer $P..."
$BIN/lpadmin -x $P
done
return 0
fi
}
Not sure why you need the surrounding if-statement though
so that i could call the variable $printer...
will it effect my function in any way if i remove it?????
---------- Post updated at 12:19 ---------- Previous update was at 12:10 ----------
made adjustments as suggested, but its not deleting the three printers!!!!!!!
f_Delete()
{
if [ -z "$printer" ]; then
echo "\n\t Printer to be deleted"
return 1
else
for P in $printer; do
echo "\n\t Deleting printer $Printer !!!"
$BIN/lpadmin -x $P
done
return 0
fi
}
this is the errors!!!
+ echo 0117bd1 2201bl7 5001bl1
0117bd1 2201bl7 5001bl1
+ f_Delete
Deleting printer !!!
lpadmin: The printer or class was not found.
Deleting printer !!!
Deleting printer !!!
Why is not picking up my three printers and deleting them????
Variables in UNIX, as in most languages are case-sensitive.
$Printer
is not the same as
$printer
In any case...
This:
echo "\n\t Deleting printer $Printer !!!"
Should be
echo "\n\t Deleting printer $P !!!"
Can you show that the printers were not deleted?
The error you got is because one of the printers you are trying to delete doesn't exist.
A small change:
f_Delete()
{
if [ -z "$printer" ]; then
echo "\n\t Nothing to do!"
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
}
Now to recreate the printers deleted!!!
My function to recreate the printers i have as follows:
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
}
The reason for so many variables, is because we have printers with different drivers, ports,descriptions,locations and filters.
or would it be possible to re-create just these three printers with the info we have in diffs.txt
device for 0117bd1: lpd://172.25.29.60:515
device for 2201bl7: socket://172.25.11.170:9100
device for 5001bl1: lpd://172.25.11.203:515
---------- Post updated at 15:46 ---------- Previous update was at 13:56 ----------
script is hanging during execution of create function
#!/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 problem with syntax within my script..any help will do?????
The -x option specified at the command level (has you did) or inside the script (at main level) has no effect inside functions.
If you want to debug a function, add the set -x command in the function body.
Where in the function
itried at the beginning of the function but receive a error
+ f_Create
psset: Unknown or ambiguous option `-x'.
psset: Try `--help' for more information.
Adding printers !!!!
Enter Printer Name: 0117bd1
---------- Post updated at 11:06 ---------- Previous update was at 09:56 ----------
The pressure is mounting, i need some help.
the script just not seem to continue after entering the printer.It stays hung.Any assistance will be highly appreciated.
i have entered the set -x at the start of the function but it does not give me any joy
here is the function i am trying to execute
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
}
The reason there are 12 lines is because $i contains the entire contents of diffs.txt without the line terminators. There are twelve distinct space-separated elements. The variable $i is not referred to at all in the script so all that happens is the "printer=" line is executed 12 times. I cannot explain how the "printer=" line outputs anything but when inside a shell script it does.
Anyway the "for" loop is not required or desirable.
If we remove the loop completely and make sure that awk has a filename parameter, it now works:
printer="$(awk -F: '{ print $1 }' diffs.txt | cut -c 11-18)"
echo $printer
0117bd1 2201bl7 5001bl1
Okay, we now have the (unchanged) situation where $printer contains 3 printer names. This is not desirable when we look at the contents of f_Create.
Suggest you change the "printer=" line above to use a different variable name (e.g. "printer_list="), then look at where you want a list against where you want a single printer.
The f_Create function contains "read printer". This overwrites the variable $printer. The "read printer" line is not required - it is probably what is hanging the script because the input channel is already tied up with the "for" loop.
Further correction: The shell "read" statements conflict with the "for" loop. I think this script needs a redesign.
Footnote. To answer your earlier question it would be possible to automate the whole process but only if your diffs.txt file contains all the information in (which it does not) in a suitably delimeted format.
Thanks methyl..
Your input has been of great help...I have made the changes as you suggested.
I have changed the create function by removing the read $printer
The function now does create my printers from the #printer_list EXAMPLES
+ f_Create
+ [ -z 0117bd1
2201bl7
5001bl1 ]
+ echo \n\t Adding printers !!!!
Adding printers !!!!
+ /usr/lbin//lpadmin -p 0117bd1 -E -D -L -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Adding printers !!!!
Adding printers !!!!
+ /usr/lbin//lpadmin -p 2201bl7 -E -D -L -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Adding printers !!!!
Adding printers !!!!
+ /usr/lbin//lpadmin -p 5001bl1 -E -D -L -i /u1/cups/mac/_filter -v ://:
lpadmin: No such file or directory
+ echo \n\t Printer created
Printer created
but without the required parameters.
lpstat -v 5001bl1
device for 5001bl1: ///dev/null
The driver=lpd or socket,Ip address,port=515 or 9100 are vital to create the printers...
I did some research and found something like this
while IFS=":" read printer driver IP port
Can it work from this????????
---------- Post updated at 14:08 ---------- Previous update was at 08:27 ----------
Must be a long weekend??????
asisstance will be highly appreciated.