I have a script A which call a script G . Inside script G I cannot change any thing (don’t have write access).
Inside Script G :
ExitProcess ()
{
case $1 in
"0" ) echo "$0: Finished successfully."
exit 0
;;
*) echo "$0: Unknown return status ($1)"
exit $1
;;
esac
}
Due to which I am exiting from Script A , how to stop this ?
Script A:
check_status()
{
UserName="sbrk6"
MachineName="sn26"
Tstatus=`ssh -f -T ${UserName}@${MachineName} ps -ef | grep -w "Manager 1 PR" | egrep -v "grep|less|vi|more"`
Cstatus=`ssh -f -T ${UserName}@${MachineName} ps -ef | grep -w "gt1" | egrep -v "grep|less|vi|more"`
if [ "$Tstatus" ]
then
if [ "$Cstatus" ]
then
Gstatus=`ps -ef | grep -w "Gth_Hndl" | egrep -v "grep|less|vi|more"`
if [ -z "$Gstatus" ]
then
genth_start
fi
fi
else
if [ -z "$Tstatus" ]
then
if [ -z "$Cstatus" ]
then
Gstatus=`ps -ef | grep -w "Ghfdjdjd" | egrep -v "grep|less|vi|more"`
if [ "$Gstatus" ]
then
genth_stop
fi
fi
fi
fi
}
genth_start()
{
echo START
. GD1_Sh
}
genth_stop()
{
echo STOP
. G_Sh
##This is the Script G ###
}
while :
do
check_status
done
Want this while loop to continue until I kill this script
If you can’t change Script G, then it is probably easiest to arrange to run it as a separate process rather than using the
.(dot) command to run it in the current process.If Script G can only be used in the dotted mode, then you could write a third script, call it Script Z, which is designed to run Script G and exit, while your Script A continues happily (reporting the error from Z exiting, then doing whatever is appropriate).
If that is not feasible either, then you could use
evaland$(...)carefully, so that when the functions from Script G that contain exit statements actually exit, they are running in a sub-shell and not in your main shell. This is fiddlier to do than running Script G separately, whether wrapped with Script Z or not, so I’d use one of those mechanisms first.