Você deve ser capaz de fazer algo assim:
#/usr/bin/env bash
## We will use this function later to check if
## everything has been correctly started.
function check_if_init_OK {
## You will need to edit this to add whatever services
## you have to check for.
c=0; ## This is a counter, initialized to 0
## For each of the service names you are interested in.
## to add more, just put them after freeswitch, separated by a
## space they way they are now (e.g. a b c).
for service in freeswitch foo bar baz; do
## Every time this loop is executed, $service will be
## one of the services you put in the list above. The
## script will run screen -ls and search for the name of the
## service. If it finds it, it will increment the counted $c by one.
## That is the meaning of '&&' in bash, x &&y means do y if x
## was successful.
screen -ls | grep $service >/dev/null 2>/dev/null && let c++;
done
## This just makes the function return $c which at this point
## will be how many of the the services you gave in the list have
## been found.
echo $c
}
## Run the first script -> stop app
script1.sh &
## Wait until it has stopped running
while screen -ls | grep script1.sh; do sleep 1; done
## Run the second script -> start app and wait 15 seconds
script2.sh && sleep 15
## Check that everything has started OK. The function
## will return the number of services of interest that
## are up and running. While this is less than the number
## of services of interest, re-run script2.sh and check again.
## This loop will run the check_if_init_OK function until the
## number returned (the number of running services of interest) is
## 3. You should change the 3 to reflect the actual number of services
## you are looking for. So, as long as some services have not started,
## run script1.sh and then script2,sh and check if this time eveything
## has started OK. This loop will only exit when everything is working OK.
while [ "$(check_if_init_OK)" -ne 3 ];do
script1.sh && script2.sh
done