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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

synthax error using do command 1

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
i am trying the following
Code:
while IFS =: read printer drv IP port
do
echo -e "$ printer: \ n \
drv: \ t $ drv \ n \
IP: \ t $ IP \ n \
port: \ t $ port \ n \"
done < diffs.txt

BUT RECEIVING following syntax error:
Code:
syntax error at line 37 : `do' unmatched

Something is amiss
 
Replace this:
\"
with this:
"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you, it works...now
but how can i use the variables in a if statement...
IF $printer = 2201bl7
then
lpadmin command to recreate ????
 
Before you start writing code (or copying it from somewhere), you need to have a clearer idea of what you're trying to achieve. I've noticed with many of your posts recently you have put together lots of code, but you don't really seem to have a good idea of how it should actually work.

It would be a good exercise to write your code in plain english first (i.e. pseudo-code) before trying to plunge in and implement it. That would also make your requirements clearer to both yourself as you write it, and to us when you have questions. For example, something like this:

Code:
for each printer on hosta

   save hosta printer configuration in variables

   if that printer doesn't exist on hostb
       construct command-line options from saved variables
       run command on hostb to create printer
   end if

end for

This is also the reason why you often don't get answers to your questions. We can see that you are going to need lots of hand-holding to get to the ultimate solution because you don't appear to have a good idea of where you are going.

I hope that helps.

Annihilannic.
 
That's true annihilannic...I am no programmer..but my job requires me to do scripting..and i want to learn...

I was thinking along the lines:
Code:
IF printer = from my list;
then
do 
$BIN/lpadmin -p "$P" -E -D -L - /u1/cups/mac/"$filt"_filter -v "$driv"://"$
ip":"$port"

using the variables from the above while do.

I sometimes understand what is needed to do..but confuse myself with the many options available, to get the ultimate solution.
 
thank you, for the advice
this is what i have now done.
I've setup variables as follows:
Code:
drv=`awk -F"[ :]|//" '{print $5}' diffs.txt`
echo $drv
IP=`awk -F"[ :]|//" '{print $7}' diffs.txt`
echo $IP
port=`awk -F"[ :]|//" '{print $8}' diffs.txt`
echo $port

Used the function, to create the printers as follows
[/code]
f_Create()
{
set -x
if [ -z "$printer_list" ];then
echo "$printer "
return 0
else
for P in $printer_list; do
echo "\n\t Adding printers $P !!!!"
$BIN/lpadmin -p "$P" -E -D "$drv"://"$IP":"$port"
done
echo "\n\t Printer $printer created"
fi
}
[/code]

when i run my script, and function gets executed, i get the following:
Code:
+ echo \n\t Adding printers 5001x02 !!!!

         Adding printers 5001x02 !!!!
+ /usr/lbin/lpadmin -p 5001x02 -E -D lpd
socket
socket
lpd
lpd
lpd://172.25.29.60
172.25.44.188
172.25.11.170
172.25.11.203
172.25.12.160
172.25.12.160:515
9100
9100
515
515
515
+ echo \n\t Printer  created

         Printer  created
ITS ADDING THE PRINTERS but not with my variables????
 
If your senior expects you to do lots of systems programming, then you should try and get him to send you on a programming course.

In the code above you are trying to process lots of printers, but you are only writing code that would work for one printer. You need to implement some kind of loop logic around it so that it correctly handles one printer at a time.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top