how to make my own file as a running log file in bash

Hi,
I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information.

#!/bin/bash
# 
echo "Hello" >> /tmp/ZZ/OUT
sleep 10
echo "World" >> /tmp/ZZ/OUT
sleep 10
echo "---------end -----------" >> /tmp/ZZ/OUT
sleep 5

                  cat OUT 
Hello
Hello
Hello
World
World
World
---------end -----------
---------end -----------
---------end -----------

I would like to know is there any possibility to get consistent output like log file (/var/log/message) for any number of time script invocation. like below.

Hello
World
---------end -----------
Hello
World
---------end -----------

Thanks in advance.
-regards
guest.

processes which are gonna invoke your script can write output into different files. say psid.out.log for example.

if you want only one log file, you may consider to add some prefix to each appended text, to indicate the log message was from which process.

Thnx for the suggestion.
however I want some sort of syncronization technique to my script so tht my output is consistant.Otherwise I need a mechanism how the log file(/var/log/messages) use to append automatically.

out1=$( command1 )
sleep 10
out2=$( command2 )
sleep 10
printf "%s\n" "$out1" "$out2" "---------end -----------" >> /tmp/ZZ/OUT
1 Like

Thanks a lot!!!.
This is working fine which as per my expectation.... gr8..:b: