Need help with this challenging code....

Hello All,

I am new to this forum, and the reason I came here is to seek solution from the experts.

I have written following wrapper script, it was running fine from past couple of months, until last week.
When one of the function in the script which suppose to login through ssh to the external server and run the script to start/stop the tibco or http get hanged. The script hanged till 14 hours when it comes to our notice that nothing is running.

Now my problem is that when the script executes the external scripts on which I donot have any control through ssh. It looses the control, and become fully dependent on the external script to pass the control back to my script where I can decide that the external command or scipt ran successfully or not.

Can there be a way by which my script be able to do the following?

1- Able to identify if the external scripts or commands hangs or taking longer time then expected?
2- Able to kill the external commands or script plus all the subsequent scripts and report an error?
3- OR can I built the timeout for each function?

Any help will be highly appreciated as I have tried everything but my Unix skills aren't that good that I could resolve this issue on my own.

Regards
Tajdar

F_STOP_HTTP()
{
# This stops the HTTP server for CRM so no one can log on.
set -x
log_message "Stopping the CRM HTTP server on ${HTTP_HOST}."

su - jxadmin -c "ssh ${HTTP_HOST} '/opt/app/IBMIHS/bin/apachectl -d /opt/app/IBMIHS/ -f /opt/app/IBMIHS/conf/httpd.conf.was${ENV}.ChordiantServerCobal -k stop; echo $?'"

if [[ $? -eq 0 ]]
then
log_message "Success: HTTP server stopped successfully."
else
log_message "Error: HTTP server cannot stop, exiting. Please check the detail Logs."

mail_error
echo `date`": Script Failed Exiting."
exit 1;
fi

}
# ----------------------------------------------------------
# MAIN BIT
# ----------------------------------------------------------

F_STOP_HTTP

## End of Script...
echo `date`": Script Completed Successfully."
exit 0;

and the following program:

freshmeat.net: Project details for limit

I posted a solution to a similar problem here:

http://www.unix.com/shell-programming-scripting/98600-killing-process-children.html#post302283088