loop of killing and calling process

I make two process killing and calling one process
I want to do this repeatedly many time between the interval(sleep)
What will be the command to do this, can you make as one
do use sleep between and run clear the memory(sh sync.sh)
I need your advice,

the script will be like this

killps
sh sync.sh
sleep 30
callps
sleep 60
killps
sh sync.sh
sleep 30
callps
sleep 60

This is callps

#!/bin/sh

pspid=`ps -ef | grep "cap -d" | grep -v grep | awk '{print $2}'`
psmcn=`who am i | awk '{print $6}'`
logfile='/nccbs/bin/ps_reset.log'
if [ "$pspid" -eq "" ]
then
clear
echo " "
echo " " >> $logfile
echo `date '+%Y-%m-%d %H:%M:%S'`' Initialization Started '$psmcn >> $logfile
echo "PS Initializing......."
echo " "
sync.sh
echo `date '+%Y-%m-%d %H:%M:%S'`' PS Started '$psmcn >> $logfile
# /nccbs/bin/xterm -e cap -d
cap -d
sleep 2
echo `date '+%Y-%m-%d %H:%M:%S'`' PS Stopped '$psmcn >> $logfile
echo " " >> $logfile
else
echo
echo
echo Process Already Started...
echo " " >> $logfile
echo `date '+%Y-%m-%d %H:%M:%S'`' Process Already Started...' >> $logfile
echo " " >> $logfile
echo
echo
fi

This is killps

#!/bin/sh

pspid=`ps -ef | grep "cap -d" | grep -v grep | awk '{print $2}'`
psmcn=`who am i | awk '{print $6}'`
logfile='/nccbs/bin/ps_reset.log'
echo
if [ "$pspid" -eq "" ]
then
echo
echo PS is not running
echo `date '+%Y-%m-%d %H:%M:%S '`' PS Not running' >> $logfile
echo
else
# echo Provision PID : $pspid
# echo $psmcn
kill -9 $pspid
kill -9 $pspid
echo `date '+%Y-%m-%d %H:%M:%S '`' PS [ '$pspid' ] Killed '$psmcn >> $logfile
echo Process [ $pspid ] Killed Successfully
fi

echo ; echo

Don't make seperate scripts for this but put all in 1 script with functions.

Something like.

#!/usr/bin/ksh

killps()
{
pspid=`ps -ef | grep "c[a]p -d" | awk '{print $2}'`
# notice the [] around the "a" in "cap", it avoids using "grep -v grep"
echo ""
if [ "$pspid" -eq "" ]
then
echo ""
echo PS is not running
echo `date '+%Y-%m-%d %H:%M:%S '`' PS Not running' >> $logfile
echo
else
# echo Provision PID : $pspid
# echo $psmcn
kill -9 $pspid
kill -9 $pspid
echo `date '+%Y-%m-%d %H:%M:%S '`' PS [ '$pspid' ] Killed '$psmcn >> $logfile
echo Process [ $pspid ] Killed Successfully
fi

echo ""
echo ""
}

callps()
{
pspid=`ps -ef | grep "c[a]p -d" | awk '{print $2}'`
if [ "$pspid" -eq "" ]
then
clear
echo " "
echo " " >> $logfile
echo `date '+%Y-%m-%d %H:%M:%S'`' Initialization Started '$psmcn >> $logfile
echo "PS Initializing......."
echo " "
sync.sh
echo `date '+%Y-%m-%d %H:%M:%S'`' PS Started '$psmcn >> $logfile
# /nccbs/bin/xterm -e cap -d
cap -d
sleep 2
echo `date '+%Y-%m-%d %H:%M:%S'`' PS Stopped '$psmcn >> $logfile
echo " " >> $logfile
else
echo ""
echo ""
echo Process Already Started...
echo " " >> $logfile
echo `date '+%Y-%m-%d %H:%M:%S'`' Process Already Started...' >> $logfile
echo " " >> $logfile
echo
echo
fi
}

logfile='/nccbs/bin/ps_reset.log'
psmcn=`who am i | awk '{print $6}'`

while true
do
killps
sh sync.sh
sleep 30
callps
sleep 60
done

If this shouldn't go on endlessly but just e.g. 100 times

COUNT=1
while [ ${COUNT} -le 100 }
do
killps
sh sync.sh
sleep 30
callps
sleep 60
((COUNT=${COUNT}+1))
done

I don't know what "sync.sh" is supposed to do, but you could make it a function as well within the script.