shell scripting: help appreciated

no at spam at mgedv.net nospam at mgedv.net
Mon Jul 3 08:27:06 UTC 2006


short and weird problem description (from my point of view):
/bin/sh stops working correctly with a content-controlled do-loop.


the shell-script layout is as follows:
(it's not that trivial, just to show the meaning)
---------------------------------------------------------------
/test/foo.conf (originally ~60 lines):
test1		testval1		optional_testval1
test2		testval2		optional_testval2

/test/foo.sh (this is the original loop code):
cat "$g_dir_etc/compile.lst"|\
sed -e 's-^     *--g'|\
sed -e 's-^ *--g'|\
grep -v '^#'|\
sed -e 's-#.*$--g'|\
grep -v '^$'|\
while read gh_name gh_src gh_srcdir
do
	<set some vars here>
	/bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
	<do some stuff here>
done;

/test/foo_sub.sh:
<we do very much stuff in here, like compiling programs etc...>
---------------------------------------------------------------

if i change the line
	/bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
to
	echo /bin/sh -c subprogram.sh $h_val1 $h_val2 $h_opt1;
the program loops for all records in the foo.conf correctly.

if i remove the "echo" keyword, the sub-script get's executed,
but the shell terminates as if there were lesser records in
the foo.conf file!
i scripted as many debug messages as possible, for every loop
they get executed and there are no errors/etc... happening.
and interestingly, the execution stops always on the same record!
if i comment out some records of my foo.conf, the sub-shell gets
executed for more records.
it seems like something with a buffer or somewhat, but i'm not
a debugger/c-guru, so i don't know where to start here... maybe
i'm using a wrong technique for looping?

some facts:
conf-file is readable and doesn't change during execution
the scripts also don't change during exec
we're running on 6.1-RELEASE with 2GB RAM and a XEON 2.8
no errors/warnings during exec-time from kernel or daemons
fs is fine, fsck is happy! everything runs /bin/sh.
the whole scripts runs currently ~45min.
if i change the subshell to an empty script with just "hi i'm here"
and "exit 1;" the loop works for all records in the .conf file.

any ideas, what the hell is going on here?




More information about the freebsd-questions mailing list