sequential running for 2 scripts

Hello

I have a script that has 2 scripts that must be executed one after the other.
however, when I run the script, the 2 sub-scripts are run in parallel.

any idea how to fix this without using sleep command?

thank you

use locks .... simple solution is use wait ......using pid of process

Have script one create a file "script1running" when it starts, and delete it when done.

Embed some kind of wait or delay to make sure script one got a chance to create that locking file.
Then have script two in a loop checking for the existence if "script1running". Once the file does not exist, then script two can continue.

Hi

Currently I am using this:

Fct1()
{
touch /tmp/lock$$
...
rm /tmp/lock$$
}
Fct2()
{
while [ -f /tmp/lock$$ ]
do
sleep 30
done
...
}

Is there a better way to synchronize? (I still need to test the above solution )

thank you.

hi

can you please help in this?

thanks

Checking the lock and creating the lock should be done as a single atomic operation, otherwise after the lock is not found and before it is created a concurrent process could also see no lock and decide to go on.

This is one way to do the check and the creation atomically:

until mkdir /tmp/lockdir 2>/dev/null; do
  sleep 1
done

The problem with mkdir is that if the script is aborted then a fictitous lock is left behind.
With trap you can provide a handler to remove the lock for any termination reason, but a SIGKILL cannot be trapped.

Hi Joyeg,

are you suggesting something like this-

#!/usr/bin/ksh
echo "this is a script that runs two script one after the other"
./dateformat.sh > script1running; wait 5 ; rm -f script1running;
for file in *;do
if [ $file = "script1running" ]
 then
   echo "the script1running file is there"
  else
   ./sample.sh
   break
  fi
   done

Thanks
NT

I tried another approach

fct1
while [ ! -f $ORACLEHOME/root.sh ]
do
sleep 200
done
fct2

still fct2 runs without waiting for fct1 to end