multiple processes overlap

Hello

I've got a script that creates multiple processes, in ksh, to bcp out 6 tables at a time. In the script, we write messages to the log to show our progress; most of the time, the log messages are nice and neat with one per line, like they should be. But every once in awhile, at random, the messages will "overlap" each other, and I can't see why. I tried putting a sleep 1 just before we write to the log file, but the log messages still overlap.

Here is a small portion of the log file:
________________________________________________
01/07 13:37 CER_PZME_MENU_ENT..chgenv01 - bcp out started
01/07 13:37 CER_PZMG_MENU_GRP..chgenv01 - bcp out finished successfully
01/07 13:37 CER_PZCI_C0L1I/E0N7T 1_3U:.3.7c ChEgRe_nPvZ0A1P -_ bAcPpP o.u.tc fhigneinsvh0e1d - s buccpc oeusts ffiunlilsyhed successf
ully
01/07 13:37 CER_PZME_MENU_ENT..chgenv01 - bcp out finished successfully
01/07 13:37 CER_PZCO_VALRLSE..chgenv01 - bcp out finished successfully
...
...
01/07 13:39 NWX_NSCT_SCHD_TYPE..chgenv01 - bcp out finished successfully
01/07 13:39 NWX_NSCV_SCH_VALUE..chgenv01 - bcp out fini0s1h/e0d7 s 1u3c:c3e9s NsWfXu_lNlSyHC_SCHEDUL
ES..chgenv01 - bcp out finished successfully

____________________________________________________

and here is a little bit of the code that we use. The echo statement at the bottom is what is being written to the log; I can't see why this "overlap" problem is random, and doesn't effect all the messages.
_____________________________________________________
bcp_with_error_check $dbname..$stbl out $sfile_main -$mode -b10000 -A8192 -e$sfile_error -U$suser -S$senvname -P$spass > /dev/null
# Write to the log the table date/time -- completed
sleep 1
echo `date +"%m/%d %H:%M"` $strTableName..$dbname - bcp out finished successfully

_____________________________________________________
Any help would be appreciated. tia

Unix doesn't necessarily flush the content to disk as soon as you've called echo. It will wait for a complete block of text or will force the flush when the file descriptors are closed, typically at the end of the script. You should be able to see this effect if you create a file slowly, such as...

and monitor /tmp junk as it's being written with

It's difficult to force a flush to disk in Shell script. In Perl, you can use AUTOFLUSH ($!).
In shell, you could attempt to run the echo in a subshell - enclose the command in parentheses

although I'm not sure how succesful this would be!

Hope that helps.

Jerry

Thanks for your help; although your suggestion to put the echo statement in parentheses did not work - it pointed me in the right direction. I began to think the echo statement itself might be the culprit. In the script, I changed the echo statements to printf statements (with an explicit new line character). Now, the log files look good - no more overlapping messages - and the text file that I create in the script looks good as well.