|
From: Friedrich L. <fl...@fl...> - 2004-02-01 10:55:53
|
Bruce Smith wrote on 01.02.2004 03:23 MET:
>>>>>Shouldn't we move firewall.rules to /etc/sysconfig/network?
>>>>>/etc/sysconfig will propably be always be selected for upgrade.
>>>>
>>>All the other init scripts are in init.d.
>>>I guess it could go either place... :-)
>>
>>Was just a thought to make it more intuitive to see which files
>>will propably need migration/copying from version to version.
>
> I don't know which place is better.
> It's easier to leave it alone. :-)
Ok.
> What's the most efficient way to check each file against a large list of
> filenames in a script?
>
> I'm thinking a bunch of lines like this isn't the best.
> [ $i = file1 ] && ..."
> [ $i = file2 ] && ..."
> [ $i = file3 ] && ..."
> ....
>
> Or a big long case statement?
> case $i in
> file1 | file2 | file3 | ... )
>
> Or putting all the files to check in a text file, and doing a:
> "[ $(grep -xc $i filelist.txt) -eq 1 ] && ..."
grep -qx $i filelist.txt &&
or
if grep -qx $i filelist.txt; then
....
fi
>
> Or something else?
>
> The grep example is the cleanest bash code, but what about performance?
> The upgrade-config script is already a little slow, and I'm more
> concerned about speed than how it looks.
>
> (my guess is still grep, but I'd like hear other thoughts)
I think you could try the following (filelist.txt becomes selectlist):
# build candidate list (a list of all available files)
....... >> /tmp/candidates
# calculate intersection of candidate list with select list
TO_SELECT=$(sort /tmp/candidates selectlist | uniq -d)
for SELECT in $TO_SELECT; do
# cycle through all the files that should be selected per default
...set variables...
done
"uniq -d" gives you those lines of both files that are equal,
so you will get exactly a list of file that exist in the current
config which should be selected per default.
--
MfG / Regards
Friedrich Lobenstock
____________________________________________________________________
Friedrich Lobenstock Linux Services Lobenstock
URL: http://www.lsl.at/ Email: fl...@fl...
____________________________________________________________________
|