I have OpenBSD 2.9 that I installed a few months ago.
I patched it with the then-current patches and then
ignored it for awhile.
I just downloaded the patches again, but I don't remember which ones
that I have already applied to my system.
Therefore I unpacked the source tree again, and I figure I will
just apply every patch all over again and I won't have a problem.
It occurred to me that if I wrote a script to automate the application
of every patch, I could save myself a little time. I could also
have the script write a log indicating which patches have been applied.
Thus I have the following plan. I extracted the instructions for applying
each patch from the patch files and put them all into a stage directory.
My apply_patch script can then read each file, execute the lines in each
file, and apply each patch correctly, logging everything as it goes.
To begin writing this script, I started out with a basic while loop
that reads in every line in a file and prints out the contents of the
line so I could see that it was reading every line.
Now we get to the problem, the print command properly prints the
contents of lines that do simple commands like cd, but when it
got to the lines that call patch and make, it began to execute them.
This can not possibly be correct behavior, as the print command should
not treat lines differently based upon their contents.
Please help me, this problem is going to make it VERY difficult to
create this script, and in the meantime, the partially applied patch
has broken several things, and now I have to perform a re-install and
apply the patches anyway.
Below are the two scripts.
First the apply_patch script.
#!/bin/ksh
logfile=/var/compile/$1.log
while read line
do
if `echo $line | /usr/bin/grep -vi for`
then
print "$line"
else
print "Do something with a for loop"
fi
print "end of if"
done < /usr/patch/scripts/$1
print "Done"
I called the above script with the name of the first patch,
which is 001_sendmail.patch.
Contents of 001_sendmail.patch.
cd /usr/src
patch -p0 < /usr/patch/stage/001_sendmail.patch
cd gnu/usr.sbin/sendmail
make obj
make depend
make
make install
Can anybody help me out here?
Werner Stolz.
Unix System Administrator
BGE, Ltd.
> Now we get to the problem, the print command properly prints the
> contents of lines that do simple commands like cd, but when it
> got to the lines that call patch and make, it began to execute them.
>
> This can not possibly be correct behavior, as the print command should
> not treat lines differently based upon their contents.
It probably falls apart on the lines with && in them. Your script doesn't
properly escape them, and the shell sees "print make obj && make", which
is interpreted as two commands.
Learning to escape strings in ksh is left as an exercise for the reader.
(I don't know how, actually.)
--
If you ever would give them a helping hand,
You can be sure they'll chop off the arm.
Never, ever, never trust a Klingon; you will always regret it.
That is not likely to be the case, as there are no && in the file that
I
am reading from. The second excerpt that I pasted is the complete
contents
of the file that is being read.
The line that is being executed inappropriately is 'patch -p0 <
/usr/patch/stage/001_sendmail.patch'.
The cd commands before and after this line are correctly echo'd to the
screen, but the above patch command and the 'make obj' command below
it
are both executed instead of printed.
Werner Stolz.
Unix System Administrator
BGE, Ltd.
'Tricky....I'll have to think about it.'
> I just downloaded the patches again, but I don't remember which ones
> that I have already applied to my system.
>
> Therefore I unpacked the source tree again, and I figure I will
> just apply every patch all over again and I won't have a problem.
You could also use CVS to track the sources of the -stable branch.
> #!/bin/ksh
>
> logfile=/var/compile/$1.log
>
> while read line
> do
> if `echo $line | /usr/bin/grep -vi for`
That means: Execute $line if it doesn't contain "for", and branch
depending on the result of the execution.
I suggest you go and find some tutorial on basic shell scripting.
--
Christian "naddy" Weisgerber na...@mips.inka.de
Why would `echo $line` execute the command contained in the variable
line?
I would expect if I had put `$line` it would execute it as a command,
but echo should just echo it.
Werner Stolz
Unix System Administrator
BGE, Ltd.
Okay, this gets a little weirder. Since I had this partially applied
patch, I did a re-install of 2.9 on my system. This corrected the
problems caused by the partial patch. Like magic, my print command
began to work properly again.
I thought this was mighty weird, but it made me more cautious. I did
a fresh install on a different system. Wiiped out everything that had
been there before, then copied the relevant scripts across.
I begain testing the script again on the new box. Guess what? The
print command behaved exactly like it had the first time. It tried to
execute commands inside the variable instead of printing them to the
screen.
I performed an upgrade install on the new box, and the print problem
went away again, it began to behave in the expected fashion.
While this problem can now be considered closed, does anyone know why
a clean install ends up with a broken Korn shell print, while the
upgrade fixes it?