In fact there are some problems with your code, but overall it looks quite OK. Lacking the tools you work with i cannot test it, though, so some general remarks is all the help i can give you.
asteriskbin=`which asterisk`
Basically, this is a good attempt at enhancing runtime security, but: either "asterisk" is already within the PATH, then your statement would be superfluous, or it is not - would your statement help that in any way?
The answer is: no. Most binaries in Unix have fixed places anyway, so your "asterisk" binary might always reside in "/usr/bin/asterisk" or so. If this is not the case and you really need to find out where it is, then your script should react in some way if it is not to be found. And, by the way: NEVER USE BACKTICKS! POSIX process substitution is done with "$(...)". Having said this, consider the following:
asteriskbin="$(which asterisk)"
if [ ! -x "$asteriskbin" ] ; then
echo "ERROR: asterisk executable not available, aborting...." >&2
fi
Generally you should strive to use as few commands as possible, because every "fork()" system call is expensive. I do not know the output you are trying to check here, but i suppose it is "Status" and "OK" on the same line:
checktrunk=`$asteriskbin -rx �sip show peer $trunk� | grep Status | grep -wc OK`
Furthermore, you should ALWAYS quote your string variables. If "$asteriskbin" contains a space (this would be a legal filename in Unix) your commadn would not work any more. The following is a suggestion as to how this is done easier. Maybe you have to adjust the regular expression in "grep" if the output is not like i supposed it to be:
checktrunk=$("$asteriskbin" -rx "sip show peer $trunk" | grep -c "Status.*OK")
Another this is to try to work strictly typed, even if the shell is not requiring it. If you want to create an integer variable, then create one explicitly:
typeset -i interval=10
The following is a common misconception related to that:
if [[ $checktrunk == 0 ]]; then
"test" (and its built-in sibling "[[") is strictly distinguishing between string comparisons and integer comparisons. "==" is an operator for strings only. Because you want to compare the integer values of "0" and "$checktrunk" you have to use the integer equivalent, which is "-eq":
if [[ $checktrunk -eq 0 ]]; then
I hope these pointers help. If you need more support just call back.
bakunin